This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-31
Channels
- # aleph (8)
- # announcements (11)
- # aws (1)
- # babashka (7)
- # beginners (104)
- # calva (52)
- # clara (1)
- # clj-kondo (28)
- # cljdoc (8)
- # cljsrn (2)
- # clojure (20)
- # clojure-europe (8)
- # clojure-uk (1)
- # clojurescript (26)
- # core-typed (3)
- # datomic (6)
- # holy-lambda (1)
- # jobs (1)
- # jobs-discuss (14)
- # malli (7)
- # pathom (31)
- # polylith (19)
- # re-frame (8)
- # reitit (1)
- # releases (1)
- # shadow-cljs (5)
- # tools-build (92)
I guess everyone is bored on the benchmarks, but updating docs, added plumatic schema to the benchmark comparison. The code looks legit :thinking_face:
(def data {:x "true", :y "1", :z "kikka"})
(def expexted {:x true, :y 1, :z "kikka"})
(spec/def ::x boolean?)
(spec/def ::y int?)
(spec/def ::z string?)
;; clojure.spec 19µs
(let [spec (spec/keys :req-un [::x ::z] :opt-un [::y])
transform #(st/coerce spec % st/string-transformer)]
(assert (= expexted (transform data)))
(cc/quick-bench (transform data)))
;; plumatic schema 2.2µs
(let [schema {:x schema/Bool
(schema/optional-key :y) schema/Int
:z schema/Str}
transform (sc/coercer schema sc/string-coercion-matcher)]
(assert (= expexted (transform data)))
(cc/quick-bench (transform data)))
;; idiomatic clojure 290ns
(let [transform (fn [{:keys [x y] :as m}]
(cond-> m
(string? x) (update :x #(Boolean/parseBoolean %))
(string? y) (update :y #(Long/parseLong %))))]
(assert (= expexted (transform data)))
(cc/quick-bench (transform data)))
;; malli 72ns
(let [schema [:map
[:x :boolean]
[:y {:optional true} int?]
[:z string?]]
transform (m/decoder schema (mt/string-transformer))]
(assert (= expexted (transform data)))
(cc/quick-bench (transform data)))
btw, got the AST registry references working, could push 0.7.0 as soon as have verified it works on real projects. Then, away from perf, back to features.
btw, I have a pretty extensive getting started guide which is probably ready for initial contribution. Which format would you like it in? adoc/md/org?
looking forward to this! If the docs would be part of the repo, then adoc / md, so that github & cljdoc can render these. I have wanted to move to adoc, but hadn’t had time to learn the syntax differences….
[metosin/malli "0.7.0-20211031.202317-3"]
is out, perf + new Schema AST. Will run it against work projects next week before making a real release. Has breaking changes, mostly in the extender API, so please read the https://github.com/metosin/malli/blob/master/CHANGELOG.md#070-20211031202317-3-2021-10-31.