Fork me on GitHub
#malli
<
2023-06-08
>
sparkofreason15:06:43

When using providers, is there a way to infer that a string valued property is an enum?

p-himik16:06:28

Judging by the source code, I don't see any way other than

(mp/provide
  [(mp/-hinted "a" :enum)
   (mp/-hinted "b" :enum)])
=> [:enum "a" "b"]

p-himik16:06:10

Ah, hinting just the first value works as well:

(mp/provide
  [(mp/-hinted "a" :enum)
   "b" "c" "d"])
=> [:enum "a" "b" "c" "d"]

sparkofreason16:06:53

Thanks. My case is more like digging in to a map. So given something like:

[{:data {:stage "foo"}}
 {:data {:stage "bar"}}
...]
I'd like to infer [:map [:data [:map [:stage [:enum "foo" "bar"]]]]].

sparkofreason16:06:44

So maybe the correct question is how to hint a specific property.

p-himik16:06:04

(mp/provide
  [{:data {:stage (mp/-hinted "foo" :enum)}}
   {:data {:stage "bar"}}])
=> [:map [:data [:map [:stage [:enum "foo" "bar"]]]]]

👀 2
sparkofreason16:06:52

Oh, now that is cool. Thanks!

👍 2
roklenarcic19:06:26

When my [:fn pred] pred function throws some exception I only get an empty message

roklenarcic19:06:33

how do I get the actual exception

p-himik19:06:15

No built-in way. But if that exception has :type in its ex-data, that will become a part of the reported error.

roklenarcic20:06:01

Unfortunately it doesn’t, the exception was :

Execution error (IllegalArgumentException) at tick.protocols/eval11136$fn$G (protocols.cljc:88).
No implementation of method: :date of protocol: #'tick.protocols/IExtraction found for class: nil
so what I got was almost like a silent failure