This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-03
Channels
- # announcements (1)
- # babashka (31)
- # babashka-sci-dev (53)
- # beginners (34)
- # calva (54)
- # cider (15)
- # clj-kondo (9)
- # clojure (115)
- # clojure-dev (19)
- # clojure-europe (21)
- # clojure-nl (1)
- # clojure-norway (78)
- # clojurescript (10)
- # clr (9)
- # community-development (9)
- # core-async (24)
- # cursive (18)
- # datomic (59)
- # emacs (43)
- # figwheel-main (2)
- # fulcro (4)
- # graphql (4)
- # malli (7)
- # meander (12)
- # nbb (14)
- # off-topic (22)
- # polylith (9)
- # re-frame (5)
- # reitit (3)
- # releases (1)
- # shadow-cljs (36)
- # sql (1)
- # tools-build (23)
- # xtdb (13)
Can I instrument outside code?
Looks like =>
would have to be modified to use the given symbols namespace, but otherwise works well! Maybe I’ll open a PR
what's the right way to "unwrap" a :maybe
in a map?
[:map [:x [:maybe :int]]] => [:map [:x :int]]
I can't quite figure out how to use malli.util/update(-in)
to accomplish this. Do I need to use a walker instead?Just for one specific field or traversing the schemas and changing all maybe schemas?
All schemas implement the LensSchema
, so you can work in same way as with clojure.core + normal data:
With clojure core:
(update {:x [:int]} :x get 0)
; => {:x :int}
With Malli:
(mu/update [:map [:x [:maybe :int]]] :x mu/get 0)
; => [:map [:x :int]
when implementing malli.util
, there was a quick discussion what if we just implemented the Clojure Core protocols for Schemas, so you could use normal clojure core functions with them. So, this would work:
(update (m/schema [:map [:x [:maybe :int]]]) :x get 0)
; => [:map [:x :int]
… but it would have introduced problems when working with forms (which is just clojure data):
;; correct result when working with a schema
(update (m/schema [:maybe [:map [1 :int]]]) 0 get 1)
; => [:maybe :int]
;; wrong result when applied to form
(update [:maybe [:map [1 :int]]] 0 get 1)
;; => [nil [:map [1 :int]]]
… so decided to add dedicated helpers in malli.util
for schemasnice, thank you. I've been wrapping my schemas with m/schema
for fail-fast behavior in case of invalid schemas, but it does mean modifying them requires the m.util
helpers
All schemas implement the LensSchema
, so you can work in same way as with clojure.core + normal data:
With clojure core:
(update {:x [:int]} :x get 0)
; => {:x :int}
With Malli:
(mu/update [:map [:x [:maybe :int]]] :x mu/get 0)
; => [:map [:x :int]
when implementing malli.util
, there was a quick discussion what if we just implemented the Clojure Core protocols for Schemas, so you could use normal clojure core functions with them. So, this would work:
(update (m/schema [:map [:x [:maybe :int]]]) :x get 0)
; => [:map [:x :int]
… but it would have introduced problems when working with forms (which is just clojure data):
;; correct result when working with a schema
(update (m/schema [:maybe [:map [1 :int]]]) 0 get 1)
; => [:maybe :int]
;; wrong result when applied to form
(update [:maybe [:map [1 :int]]] 0 get 1)
;; => [nil [:map [1 :int]]]
… so decided to add dedicated helpers in malli.util
for schemas