Fork me on GitHub

@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

  #(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


but why are you using filter


you could so it like this : `

Alex Miller (Clojure team)16:12:26

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')

Alex Miller (Clojure team)16:12:22

sets are functions already that check membership

Alex Miller (Clojure team)16:12:59

(#{"Value1" "Value2" "Value3"} "Value1")

Alex Miller (Clojure team)16:12:08

;; yields "Value1", a truthy value

Alex Miller (Clojure team)16:12:06

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.

Alex Miller (Clojure team)16:12:27

(filter #{"Value1" "Value2" "Value3"} the-coll)

Alex Miller (Clojure team)16:12:20

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

Alex Miller (Clojure team)16:12:35

(some #{"Value1" "Value2"} coll)

Alex Miller (Clojure team)16:12:56

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!


Hi. Am coding a card game as an exercise in clojure(script). Instead of mutating the state of the cards I thought I would save the moves of each player and calculate the state from that.


That seems the functional thing to do.


Anyways, cards have to be shuffled once at the beginning of the game.


Am surpised to see clojure shuffle (or RNG in general) is not deterministic.


Is there no way to pass it a seed?