malli

https://github.com/metosin/malli :malli:
cjsauer 2021-05-08T15:25:19.259400Z

Is it possible to get malli to coerce blank strings "" into the :default value? Example:

(m/decode
  [:map [:x {:default 0} int?]]
  {:x ""}
  (mt/transformer
    mt/default-value-transformer
    mt/string-transformer))
Should result in {:x 0}

cjsauer 2021-05-08T15:34:40.259500Z

Eh, never mind. I’m thinking this isn’t a great idea. I can just strip empty strings from my data before sending it into malli for coercion. I think that’s clearer and less error-prone.

2021-05-08T17:53:35.261700Z

I noticed that the the schema:

[:schema {:registry {::cons [:maybe [:tuple pos-int? [:ref ::cons]]]}}
 ::cons]
doesn't work on http://malli.io (it doesn't produce DOT output or JSON schema) while
[:schema
 {:registry {"ConsCell" [:maybe [:tuple :int [:ref "ConsCell"]]]}}
 "ConsCell"]
this one does work. In my applications I would like to use fully qualified keyword schemas (RefSchemas) is there a way to get the transformers to work without walking the schema ahead of time and converting all fully qualified keywords to strings?

ikitommi 2021-05-08T18:06:05.261800Z

@danvingo it's a malli-sci-thing. I think one needs to define what is the current ns to sci so that ::cons works. Try :user/cons and it should work. I think @borkdude knows the answer how to make the :: work with sci...

borkdude 2021-05-08T18:14:20.262400Z

@ikitommi ::foo resolves to whatever the current namespace is, by default :user/foo

2021-05-08T19:16:44.263100Z

thanks Tommi - using :user/cons worked. I was also seeing some issues in a local repl regarding refschemas and dot. I'll try to get minimal repro

borkdude 2021-05-08T20:16:00.263500Z

Welcome to xterm-sci.
user=> ::foo
:user/foo
user=> 
https://babashka.org/xterm-sci/

ikitommi 2021-05-08T20:16:06.263600Z

hmm... Might be a edamame thing?