Fork me on GitHub

I'm wondering, after looking at the examples, I still can't really figure out how to decode a string into lowercase. I have something like this:


(def foo [:map
            {:closed true}
            [:name [:string {:max 256 :error/message "should be at most 256 characters"}]]
            [:email-address [:string {:decode/string 'clojure.string/lower-case :min 5 :max 100 :error/message "should be between 5 and 100 characters"}]]])

  (m/validate foo {:name "foo" :email-address ""}) ;; true

  (m/decode signup-request {:name "foo" :email-address ""} mt/json-transformer) ;; {:name "foo", :email-address ""}


What my objective is (in tandem with reitit), is to ensure that the email address coming in is all in lowercase. Bit of a puzzler.


Any pointers would be appreciated. Thank you.


So, got it to work, after plugging away at it for a bit:


(m/decode signup-request {:name "foo" :email-address ""} mt/string-transformer) ;; {:name "foo", :email-address ""}


difference being to use a string-transformer not a json-transformer


Although, it doesn't appear to work with reitit and it's use of json-transformer.

Roee Mazor08:04:54

Hi, I am looking at this example:

(m/validate [:alt keyword? string?] ["foo"]) ; => true
and I am wondering why it works that way, why not:
(m/validate [:alt keyword? string?] "foo") ; => true

Roee Mazor08:04:47

(the second one says false which means the alt thing actually makes it look for a sequence for some reason, how can I use :alt without a vec/seq?)

Roee Mazor09:04:52

perfect, that works perfectly ❤️

Ben Sless13:04:08

Alt is for sequence schemas. It's the | operator in regular expressions