malli

https://github.com/metosin/malli :malli:
pserrano 2021-04-30T01:46:54.070800Z

Hello. I'm looking forward to use malli in a project and will be actively learning about it in the next days 🙂

👍 2
🙌 1
ikitommi 2021-04-30T11:15:00.072300Z

hiccup:

[:schema
 {:registry
  {"Order" [:map
            [:items [:vector [:enum "SIM" "SAM"]]]
            [:delivery [:enum "letter" "email"]]]
   "SimDeliveryRule" [:fn {:error/message "If the order only includes a SIM card then the delivery method may be "letter"."
                           :error/path [:delivery]}
                      '(fn [{:keys [items delivery]}]
                         (or (not= items ["SIM"])
                             (= delivery "letter")))]}}
 [:and "Order" "SimDeliveryRule"]]
maps (maybe compact syntax via schema parsing):
{:type :schema
 :registry {"Order" {:type :map
                     :entries [[:items {:type :vector
                                        :items {:type :enum
                                                :values ["SIM" "SAM"]}}]
                               [:delivery {:type :enum
                                           :values ["letter" "email"]}]]}
            "SimDeliveryRule" {:type :fn
                               :error/message "If the order only includes a SIM card then the delivery method may be "letter"."
                               :error/path [:delivery]
                               :value '(fn [{:keys [items delivery]}]
                                         (or (not= items ["SIM"])
                                             (= delivery "letter")))}}
 :value {:type :and
         :values ["Order" "SimDeliveryRule"]}}

Yehonathan Sharvit 2021-04-30T12:00:37.074100Z

Hello there! Malli is great. A question regarding function validation (a.k.a => ): Is there a way to automatically validate that all function calls are made with proper args during development time?

borkdude 2021-04-30T12:58:55.074400Z

@viebel More info here: https://clojurians.slack.com/archives/CLDK6MFMK/p1619006445487300

Yehonathan Sharvit 2021-04-30T13:18:20.074700Z

Thank you @borkdude!

Yehonathan Sharvit 2021-04-30T13:19:05.075700Z

Given that instrumentation is not yet there in malli, what’s the common use case for :=>?

Yehonathan Sharvit 2021-04-30T13:19:18.076Z

“Only” generative testing?

borkdude 2021-04-30T13:20:28.076300Z

It's a good question, I've also wondered myself.

borkdude 2021-04-30T13:20:45.076600Z

At least you can generate some clj-kondo type hints with it =)

Yehonathan Sharvit 2021-04-30T13:22:26.077700Z

I just tried clj-kondo type hints and it’s awesome. A question related to that: where is the appropriate place for putting the (mc/emit!) function call?

borkdude 2021-04-30T13:22:58.078Z

Maybe in "component system du jour" start/reset?

Yehonathan Sharvit 2021-04-30T13:23:34.078900Z

I didn’t know you were speaking french. I don’t have any component: I am writing a library

Yehonathan Sharvit 2021-04-30T13:24:06.079600Z

I am also wondering how the emitted config from the library is going to be integrated in the application that uses the lib

borkdude 2021-04-30T13:24:41.080100Z

you probably shouldn't do this in your library, it's something an end user should do

borkdude 2021-04-30T13:25:13.080400Z

Maybe emit it as part of a pre-commit hook or something

Yehonathan Sharvit 2021-04-30T13:25:59.081100Z

why wouldn’t my library be responsible for emitting clj-kondo config for the function it provides?

borkdude 2021-04-30T13:26:24.081500Z

You can do that, but you should just commit that config into git and not generate it at runtime

borkdude 2021-04-30T13:26:46.081800Z

clj-kondo has a mechanism to pick up on configs from libraries

Yehonathan Sharvit 2021-04-30T13:30:30.082700Z

Nice!

Yehonathan Sharvit 2021-04-30T13:51:23.084300Z

Is there already a script that generates clj-kondo config from project that uses malli (basically that calls (mc/emit!)?

Yehonathan Sharvit 2021-04-30T13:51:43.084900Z

Not sure I could use babashka for that as my library might not be babashka compatible

borkdude 2021-04-30T13:52:27.085800Z

Malli is not babashka compatible either, so you should use a JVM script / function for this. You could just write a function which you can call with clojure -X my.lib/gen-clj-kondo

Yehonathan Sharvit 2021-04-30T13:52:57.086200Z

Malli is not babashka compatible. That is a sacrilege!

borkdude 2021-04-30T13:53:28.086600Z

There is an issue / petition to add malli to bb: https://github.com/babashka/babashka/issues/737 Feel free to upvote.

Yehonathan Sharvit 2021-04-30T14:01:30.087600Z

It’s not an easy choice: What’s your opinion on that? Did you upvoted or downvoted @borkdude?

Yehonathan Sharvit 2021-04-30T14:05:01.088400Z

Another question related to malli’s :=> : Is there a way to automatically generate a doc string?

ikitommi 2021-04-30T14:42:54.089200Z

@viebel function instrumentation comes with this: https://github.com/metosin/malli/issues/349

ikitommi 2021-04-30T14:44:12.089400Z

lot of things are still TODO, help welcome

Yehonathan Sharvit 2021-04-30T14:55:28.089900Z

Yeah. @borkdude pointed me to this Github issue.

Yehonathan Sharvit 2021-04-30T14:55:51.090500Z

We are starting to embrace malli at work. Hopefully, we’ll be motivated to help

Yehonathan Sharvit 2021-04-30T14:56:22.091100Z

A question related to maps. Is it possible to specify that some combination of fields are forbidden?

borkdude 2021-04-30T14:56:47.091700Z

@viebel What made you choose malli over spec or both?

Yehonathan Sharvit 2021-04-30T14:57:37.092Z

@ikitommi gave us a great talk about Malli at our dev meetup at work 😜

Yehonathan Sharvit 2021-04-30T15:00:08.093700Z

We chose malli mostly because: 1. In malli, schemas are data (not macro required) 2. spec seems stuck. Not sure if spec2 will be compatible with spec 1 3. It’s easier to contribute to malli than to spec

👍 2
1
borkdude 2021-04-30T15:05:02.095700Z

Interesting, thanks for sharing. It seems there are two ways people are choosing libraries: 1) choose core unless ... , because: bundled with clojure (no additional deps), authority (core, cognitect), promoted as "the default" 2) choose community, easier to contribute / freedom, usually more focus/options than core libs

1
Yehonathan Sharvit 2021-04-30T15:14:34.097Z

Don’t forget the data driven aspect of malli!

2021-04-30T15:23:00.097200Z

Having a version of spec alpha with a replacement in development for years doesn't exactly inspire confidence.

borkdude 2021-04-30T15:23:57.098400Z

@viebel In the defn podcast you argued that namespaced (fully qualified) keywords are a vital part of data oriented programming. spec promotes this by having specs bound to global keywords so specs describe meaning without context. Is this aspect sufficiently present in malli?

borkdude 2021-04-30T15:25:33.098600Z

(btw, I liked the podcast :))

Yehonathan Sharvit 2021-04-30T15:29:18.099300Z

Good question @borkdude. I need to play more with Malli in order to answer this question. (I am so glad you liked it)

Yehonathan Sharvit 2021-04-30T15:39:52.100500Z

Is there a way to spec a map using a key from a registry but having the key non namespace qualified?

ikitommi 2021-04-30T16:53:05.100700Z

[:map {:registry {::id :int}
 [:id ::id]]

borkdude 2021-04-30T17:59:31.100800Z

borkdude 2021-04-30T17:59:48.101200Z

The work Jim is doing is maybe interesting for the authors of malli as well

ikitommi 2021-05-02T15:29:41.119600Z

current status: https://twitter.com/ikitommi/status/1363753100268421122