Fork me on GitHub
#malli
<
2021-05-08
>
cjsauer15:05:19

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}

cjsauer15:05:40

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.

dvingo17:05:35

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?

ikitommi18:05:05

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

borkdude18:05:20

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

dvingo19:05:44

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

borkdude20:05:00

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

ikitommi20:05:06

hmm... Might be a edamame thing?