Fork me on GitHub
#malli
<
2021-02-22
>
ikitommi08:02:17

looking forward for that. I鈥檓 watching the guardrails repo, but think that鈥檚 going to be much more.

ikitommi08:02:55

> (extensible, but starting with Clojure spec)

awesome 3
borkdude08:02:14

Yeah, but will be a commercial product, so hard to contribute and see what's going on probably

dharrigan11:02:14

Looking forward to the new function schema - just saw the tweet!

馃憤 3
ikitommi11:02:11

@emccue Malli is a dynamic schema/type system, it鈥檚 not a static type system. tools like clj-kondo and typed clojure can do static analysis, maybe copilot too? Would love to see tooling get better and happy to help, but no time or skills to do anything non-trivial except to integrate into existing tooling. My point was that resolving fn arity using generative testing or 3rd party tools (clj-kondo) is a hard way to do something that would be easy to do in the core language itself. With core clojure: does a ring middleware chain would work for an async (3) arity? run and see if it throws arityexception 馃槥

ikitommi11:02:33

I鈥檓 hope and think we鈥檒l see great new developer tooling for clojure in 2021, from the community.

馃 3
ikitommi14:02:29

added more benchmarks to repo, parsing vs spec:

;; 44碌s
(let [spec (s/* (s/cat :prop string?,
                       :val (s/alt :s string?
                                   :b boolean?)))
      parse (partial s/conform spec)]
  (cc/quick-bench
    (parse ["-server" "foo" "-verbose" "-verbose" "-user" "joe"])))

;; 2.5碌s
(let [schema [:* [:cat*
                  [:prop string?]
                  [:val [:alt*
                         [:s string?]
                         [:b boolean?]]]]]
      parse (m/parser schema)]
  (cc/quick-bench
    (parse ["-server" "foo" "-verbose" "-verbose" "-user" "joe"])))

Jakub Zika16:02:13

Hi guys, I am trying to generate some random date with (mg/generate inst?) but i am not sure how :seed or :size works here. I am getting 1969 or 1970 in 99% cases. How to get a date like any >1980? Thanka dwh-replicator.database> (mg/generate inst? {:seed 20}) ;; => #inst "1970-01-01T00:00:00.000-00:00" dwh-replicator.database> (mg/generate inst? {:seed 42}) ;; => #inst "1970-01-01T00:00:00.000-00:00"

pithyless16:02:28

@jakub.zika-extern there's a good talk that explains how :seed and :size interact when writing custom generators. It even mentions the datetime problem @ 31:54. https://youtu.be/F4VZPxLZUdA?t=1911 1. The proposed solution in the talk is a custom generator that splits the datetime into separate domain bits (year / month / day / etc.) 2. A different solution (as seen e.g. https://github.com/nasa/Common-Metadata-Repository/blob/master/common-lib/src/cmr/common/test/test_check_ext.clj#L255-L257) is to change the way you choose an initial seed integer (that is used to coerce to date).

Jakub Zika21:02:17

I am mapping DB types to clojure types, so varchar(255) goes to [string? {:min 0 :max 255}] etc. I am using these derived schemas to: 1. validate data : (malli/validate [string?] "hoy") 2. generate sample data : (malli.generator/generate [string?]) When I will go for custom generators then I will have to create new validators, correct?

pithyless21:02:40

You'll need to pass in the custom generator to the spec (not necessarily when validating, but at the very least wen generating sample data).

馃憤 3
pithyless21:02:28

so instead of

[string? {:min 0 :max 255}]
you'll have to wrap it, eg:
[:and {:gen/elements ["kikka" "kukka" "kakka"]} [string? {:min 0 :max 255}]]

pithyless21:02:58

where you use one of :gen/elements, :gen/gen, :gen/fmap, etc.

pithyless21:02:18

^ I think you might even be able to just change the default :gen/gen of the specific type by modifying the malli registry globally (but then you're changing it for everything... which has its own issues ;))

pithyless21:02:58

OR, perhaps make a custom registry where you override the :gen/gen for the basic types you're interested in (e.g. instant); and then pass in the custom registry only when generating sample data

ikitommi06:02:24

no need to wrap into :and, this works too: [:string {:min 0, :max 100, :gen/min 10, :gen/max 20, :gen/fmap (partial * 2)}]

馃憤 3
ikitommi06:02:36

the default schema generators are implemented as multimethods, so for global effects, one can just re-mount generator fof 'inst? for example. not recommended.

Alex Whitt18:02:22

Would anyone like to jump on this discussion thread I created on the subreddit? (I'd prefer to keep it there so it doesn't disappear behind Slack's paywall) https://www.reddit.com/r/Clojure/comments/lpv8ok/spec_vs_malli/

馃敟 9