This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-19
Channels
- # beginners (134)
- # boot (4)
- # cider (23)
- # clara (2)
- # cljs-dev (2)
- # cljsrn (4)
- # clojure (147)
- # clojure-austin (9)
- # clojure-berlin (2)
- # clojure-dusseldorf (2)
- # clojure-france (2)
- # clojure-italy (11)
- # clojure-russia (1)
- # clojure-spec (18)
- # clojure-uk (182)
- # clojurescript (40)
- # community-development (5)
- # cursive (29)
- # datascript (6)
- # datomic (18)
- # duct (6)
- # emacs (4)
- # events (1)
- # fulcro (46)
- # hoplon (5)
- # jobs-discuss (12)
- # keechma (1)
- # luminus (7)
- # lumo (1)
- # off-topic (11)
- # onyx (9)
- # parinfer (5)
- # protorepl (1)
- # re-frame (18)
- # reagent (23)
- # reitit (2)
- # ring (5)
- # ring-swagger (20)
- # schema (1)
- # shadow-cljs (32)
- # spacemacs (1)
- # specter (2)
- # vim (26)
the new spec-tools (`0.6.1`) has a version of merge that retains the already conformed values:
(require '[clojure.spec.alpha :as s])
(require '[spec-tools.core :as st])
(s/def ::a (s/and (s/conformer str) string?))
(s/def ::b int?)
(s/def ::am (s/keys :opt-un [::a]))
(s/def ::bm (s/keys :opt-un [::b]))
(s/conform (s/merge ::am ::bm) {:a 1, :b 1}) ; {:a 1, :b 1}
(s/conform (s/merge ::bm ::am) {:a 1, :b 1}) ; {:a "1", :b 1}
(s/conform (st/merge ::am ::bm) {:a 1, :b 1}) ; {:a "1", :b 1}
(s/conform (st/merge ::bm ::am) {:a 1, :b 1}) ; {:a "1", :b 1}
@ikitommi Do you know if there is any way to conform two key aliases into one ? problematic example :
(s/def ::user
(s/keys [(s/or ::name1 ::name2)]))
Spec verifies for me already that it’s one of the other, subsequently, I don’t want to have to write (or (:name1 m) (:name2 m)) in all of my code
Is there anyway to coerce these keys into another one ?syntax is wrong, I don't think you should use a ns on the or, it should read (or ::foo ::bar)
It’s annoying to have a declarative syntax for validation, and then have to write custom code for something that trivial though… something like (alias ::name1 ::name2) would be nice, equivalent :
import com.fasterxml.jackson.annotation.{JsonIgnoreProperties}
case class User(@JsonAlias(Array("name1", "name2") name))
it would really be handy to have specs for specs, I occasionally write (s/def foo ...) or (s/fdef ::foo ...) and it's far from obvious to trace when this happens
:type java.lang.IllegalArgumentException :message Invalid match arg: clojure.spec.test.alpha$spec_checking_fn$fn__2943@786f514d
I'm importing something from some json and would like to use the namespaced map in the rest of the program