Fork me on GitHub
#malli
<
2022-10-24
>
aaron5100:10:16

Does Malli have a way to wrap input in a vector, if it’s not already a vector? I know this is a one-liner in Clojure but it’s nice to keep all the coercion together. (if (vec? x) x [x])

ikitommi04:10:31

don’t think so. what is your use case for this? input coercion?

ikitommi04:10:57

there is mt/collection-transformer https://github.com/metosin/malli/blob/master/src/malli/transform.cljc#L416-L423, but doing just just any-seq-like->target-type, not wrapping non-seqs into collections.

aaron5110:10:22

Use case is a reitit handler that accepts one or more than one multipart files. When the request has one file, the param is a map. When multiple files, the param is a vector. Would be a bit easier to handle if it was always a vector.

ikitommi11:10:50

I see, you can create a custom transformer for this. like the mt/collection-transformer but with custom functions. You can map any transformer into reitit coercion. not fun, but doable.