This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-19
Channels
- # announcements (41)
- # babashka (25)
- # beginners (11)
- # calva (15)
- # clj-kondo (34)
- # clojure (25)
- # clojure-france (2)
- # clojurescript (69)
- # conjure (1)
- # cursive (23)
- # datalog (3)
- # datomic (4)
- # deps-new (2)
- # emacs (31)
- # helix (1)
- # hoplon (1)
- # lsp (8)
- # luminus (17)
- # malli (5)
- # meander (1)
- # nrepl (7)
- # off-topic (1)
- # polylith (6)
- # portal (3)
- # reitit (15)
- # shadow-cljs (1)
- # xtdb (16)
Hi there, i'm using malli 0.6.1 to do some validation in a front-end (cljs)/back-end(clj) application. So I have a .cljc namespace where I do the validations. While this works right with clj, when I use it in cljs I see a warning message
Wrong number of args (3) passed to malli.core/-fail!
closed the performance Issue (https://github.com/metosin/malli/issues/513) - schema creation & transformation is now mostly an order of magnitude faster:
(def schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]])
(def schema (m/schema ?schema))
;; 44µs -> 3.4µs (13x)
(bench (m/schema ?schema))
;; 4.2µs -> 830ns (4.5x)
(bench (mu/assoc schema :w :string))
;; 134µs -> 15µs (9x)
(bench (mu/merge schema schema))
;; 51µs -> 3.9µs (13x)
(bench (mu/closed-schema schema))
… and opened a new one, to add first-class support for the (compact) map-syntax: https://github.com/metosin/malli/issues/543. This is really important in for building large schema systems a) via inferring or b) to be run on slow js-runtimes. Initial design (which is already 15x faster 🚀)
(def ?schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]])
(m/form ?schema)
;[:map
; [:x boolean?]
; [:y {:optional true} int?]
; [:z [:map
; [:x boolean?]
; [:y {:optional true} int?]]]]
(m/ast ?schema)
;{:type :map,
; :keys {:x {:order 0
; :value {:type boolean?}},
; :y {:order 1, :value {:type int?}
; :properties {:optional true}},
; :z {:order 2,
; :value {:type :map,
; :keys {:x {:order 0
; :value {:type boolean?}},
; :y {:order 1
; :value {:type int?}
; :properties {:optional true}}}}}}}
(-> ?schema
(m/schema) ;; 3.7µs
(m/ast) ;; 1.1µs
(m/schema) ;; 250ns (15x)
(m/form)
(= (m/form ?schema)))
; => true