This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-14
Channels
- # admin-announcements (283)
- # announcements (1)
- # aws (3)
- # beginners (24)
- # cider (32)
- # clara (13)
- # cljs-dev (1)
- # cljsjs (10)
- # cljsrn (24)
- # clojure (179)
- # clojure-dev (6)
- # clojure-russia (149)
- # clojurecup (5)
- # clojurescript (33)
- # cursive (23)
- # datomic (35)
- # devops (6)
- # emacs (1)
- # jobs-rus (11)
- # ldnclj (77)
- # lein-figwheel (1)
- # luminus (3)
- # off-topic (3)
- # om (179)
- # onyx (13)
- # proton (6)
- # reagent (60)
- # testing (1)
@codonnell: thanks . problem solved
I've got a filter that needs to check and see if a value is any one of a given list. Right now I've built it in the form
(filter
#(or (= (:my-key %) "Value1")
(= (:my-key %) "Value2")
(= (:my-key %) "Value3")))
I'm sure there must be a better way. Any suggestions?@shaun-mahood: you could also use a cond for checking
think of it instead as checking membership in a set
@roelof: I've got a set of data that I want to pull apart in a few different ways - essentially looking for the Clojure equivalent of doing
SELECT... WHERE my-key IN ('Value1', 'Value2', 'Value3')
sets are functions already that check membership
(#{"Value1" "Value2" "Value3"} "Value1")
;; yields "Value1", a truthy value
so you could use the set directly as the function in filter to return a sequence of all the elements that are one of the members of the set
Oooh that is much nicer.
(filter #{"Value1" "Value2" "Value3"} the-coll)
if you want to know if there are any values that satisfy this but don't care how many, then some
is commonly used
I knew there had to be a better way
(some #{"Value1" "Value2"} coll)
which will yield either nil (if none) or the value of the first match
Great, I'll try using the set filter, it's going to make things a lot nicer. Thanks for the help!