Fork me on GitHub
#malli
<
2021-04-16
>
schmee17:04:08

is there a way to use Malli to remove nil values in a map? :thinking_face:

Leonid Korogodski20:04:31

The oddest thing. I have two projects. Both use malli 0.2.1 (according to `lein deps :tree`). But one of them accepts the syntax `[:map [:a string?] [:b string?]]` just fine, while the other throws an error on `(restart)`:

data-spec collection [] should be homogeneous, 3 values found
Any idea what could be the cause?

borkdude20:04:18

@lkorogodski Can you try with lein clean and then run your project again?

borkdude20:04:33

You might have some left-overs in your target folder or something

borkdude20:04:06

@lkorogodski Please don't paste such long output into slack but rather use something like github gist

borkdude20:04:56

What happens when you do:

(require '[ :as io])
(io/resource "malli/core__init.class")

borkdude20:04:07

just checking if this isn't an AOT-related problem

Leonid Korogodski22:04:58

Ok, sorry. Just a moment.

Leonid Korogodski22:04:32

nREPL server started on port 64815 on host 127.0.0.1 - 
Connecting to local nREPL server...
Clojure 1.10.3
(require '[ :as io])
=> nil
(io/resource "malli/core__init.class")
=> nil
(require '[malli.core :as m])
=> nil
(m/validator [:map [:a string?] [:b string?]])
=>
#object[malli.core$_map_schema$reify$reify__21001$fn__21022
        0x5361e937
        "malli.core$_map_schema$reify$reify__21001$fn__21022@5361e937"]
That seems to work. But when I call (restart), it fails. The usage for the router is as follows:
["/my-route" {:get {:summary    "..."
                    :parameters {:header {:authorization string?}
                                 :query  [:map
                                           [:a string?]
                                           [:b string?]}
                    ;; other things
                   }}]

Leonid Korogodski22:04:59

map? works in place of [:map ...] but doesn't check enough, of course.