Check if the value is NOT in given set

17 views
Skip to first unread message

Franky

unread,
Apr 10, 2016, 4:04:54 AM4/10/16
to Plumbing and Graph: the Clojure utility belt
Hi,

(hope this question was not answered in past. I have tried to search for the answer with no luck)

Is there any nice way to check if the value is not in given set? Or at least to check if the value is not equal to some particular value (opposite of "eq")?

Example:
(schema/check (schema/not-eq 1) 1) ; leads to validation error

So far I achived something similar using coditional:
(def schema-not-equals-to-one
  (s/conditional
    #(= 1 %) <...put some validation here that always returns a validation error...>
    :else s/Any))

, but I wonder if there is anything "built-in" the library.

Regards,
Franky.


Jason Wolfe

unread,
Apr 10, 2016, 12:19:52 PM4/10/16
to Franky, Plumbing and Graph: the Clojure utility belt
Hi Franky,

Best way I can think of currently would be to use `s/pred`, e.g.

user> (s/check (s/pred (complement #{:foo :bar}) 'allowed-value) :foo)
(not (allowed-value :foo))

Cheers,
Jason
> --
> You received this message because you are subscribed to the Google Groups
> "Plumbing and Graph: the Clojure utility belt" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to prismatic-plumb...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Frantisek Kobzik

unread,
Apr 11, 2016, 4:11:34 AM4/11/16
to Jason Wolfe, Plumbing and Graph: the Clojure utility belt
Hi Jason,

thanks for the awesome tip, it works like a charm!

Regards,
Franky.

Reply all
Reply to author
Forward
0 new messages