Fork me on GitHub
#malli
<
2021-04-30
>
pserrano01:04:54

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

👍 8
🙌 3
ikitommi11:04:00

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 Sharvit12:04:37

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?

Yehonathan Sharvit13:04:05

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

Yehonathan Sharvit13:04:18

“Only” generative testing?

borkdude13:04:28

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

borkdude13:04:45

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

Yehonathan Sharvit13:04:26

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?

borkdude13:04:58

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

Yehonathan Sharvit13:04:34

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

Yehonathan Sharvit13:04:06

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

borkdude13:04:41

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

borkdude13:04:13

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

Yehonathan Sharvit13:04:59

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

borkdude13:04:24

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

borkdude13:04:46

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

Yehonathan Sharvit13:04:23

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

Yehonathan Sharvit13:04:43

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

borkdude13:04:27

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 Sharvit13:04:57

Malli is not babashka compatible. That is a sacrilege!

borkdude13:04:28

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

Yehonathan Sharvit14:04:30

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

Yehonathan Sharvit14:04:01

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

ikitommi14:04:12

lot of things are still TODO, help welcome

Yehonathan Sharvit14:04:28

Yeah. @borkdude pointed me to this Github issue.

Yehonathan Sharvit14:04:51

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

Yehonathan Sharvit14:04:22

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

borkdude14:04:47

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

Yehonathan Sharvit14:04:37

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

Yehonathan Sharvit15:04:08

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

👍 6
2
borkdude15:04:02

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

2
Yehonathan Sharvit15:04:34

Don’t forget the data driven aspect of malli!

mynomoto15:04:00

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

borkdude15:04:57

@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?

borkdude15:04:33

(btw, I liked the podcast :))

Yehonathan Sharvit15:04:18

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

Yehonathan Sharvit15:04:52

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

ikitommi16:04:05

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

borkdude17:04:48

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

ikitommi15:05:43

definitely, looks great @jimka.issy. Malli’s primary goal has been to be a data-driven runtime schema engine, but currently bending it for development time tooling to see how far we can go. Some wishes: • a schema-base case-macro, with clj-kondo based error reporting on non-exhaustive matches - for things like :or and :multi. Genus seems to have those already? • schematized fns. so many syntax options, the lisp curse? • as soon as someone builds a pluggable intellisense / code completer for clojure, happy to emit malli-mappings so that one could complete known map keys (and get errors on invalid keys - via clj-kondo).

3
ikitommi15:05:43

definitely, looks great @jimka.issy. Malli’s primary goal has been to be a data-driven runtime schema engine, but currently bending it for development time tooling to see how far we can go. Some wishes: • a schema-base case-macro, with clj-kondo based error reporting on non-exhaustive matches - for things like :or and :multi. Genus seems to have those already? • schematized fns. so many syntax options, the lisp curse? • as soon as someone builds a pluggable intellisense / code completer for clojure, happy to emit malli-mappings so that one could complete known map keys (and get errors on invalid keys - via clj-kondo).

3