This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-10
Channels
- # announcements (2)
- # babashka (15)
- # beginners (174)
- # calva (16)
- # chlorine-clover (10)
- # clara (7)
- # clj-kondo (27)
- # cljdoc (10)
- # clojars (4)
- # clojure (50)
- # clojure-europe (10)
- # clojure-gamedev (3)
- # clojure-greece (1)
- # clojure-italy (4)
- # clojure-losangeles (1)
- # clojure-nl (16)
- # clojure-sg (1)
- # clojure-spec (7)
- # clojure-uk (41)
- # clojurescript (22)
- # data-science (15)
- # datascript (38)
- # datomic (2)
- # duct (15)
- # emacs (2)
- # fulcro (110)
- # funcool (9)
- # graphql (10)
- # jackdaw (8)
- # jobs (23)
- # joker (1)
- # leiningen (15)
- # luminus (1)
- # malli (20)
- # off-topic (26)
- # pathom (5)
- # pedestal (1)
- # reitit (19)
- # shadow-cljs (78)
- # spacemacs (2)
- # sql (52)
- # tools-deps (99)
- # vim (13)
started to add programmatic helpers to malli: https://github.com/metosin/malli/pull/172
2
looks like:
(malli.util/get-in
[:map {:title "test"}
[:x [:vector
[:list
[:set
[:sequential
[:tuple int? [:map [:y [:maybe boolean?]]]]]]]]]]
[:x 0 0 0 0 1 :y 0])
; => boolean?
there is a new Protocol LookupSchema
, which is implemented for :map, :multi, :vector, :list, :set, :sequential, :tuple
.
(malli.util/select-keys
[:map {:title "map"}
[:a int?]
[:b {:optional true} int?]
[:c string?]]
[:a ::extra])
;[:map {:title "map"}
; [:a int?]
; [:b {:optional true} int?]]
so kinda like the new spec2 thing, where you can select from your schema in different contexts?
well, almost. like in schema-tools
, going to use the clojure.core functions names. There could be malli.util/select
to do things like spec2 does.
(-> [:map
[:a int?]
[:b string?]
[:c [:map
[:x int?]
[:y keyword?]]]]
(mu/select-keys [:a :c])
(mu/update-in [:c] mu/dissoc :y))
;[:map
; [:a int?]
; [:c [:map
; [:x int?]]]]
that’s the thing we have been using with prismatic schema for 3+ years now, happy with that 🙂
[:vector {:min 0, :max 10} int?]
; =>
{:name :vector
:properties {:min 0, :max 10}
:children [int?]}