Fork me on GitHub
#beginners
<
2015-12-14
>
roelof08:12:31

@codonnell: thanks . problem solved

shaun-mahood16:12:46

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?

roelof16:12:07

@shaun-mahood: you could also use a cond for checking

roelof16:12:24

but why are you using filter

roelof16:12:36

you could so it like this : `

alexmiller16:12:26

think of it instead as checking membership in a set

shaun-mahood16:12:01

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

alexmiller16:12:22

sets are functions already that check membership

alexmiller16:12:59

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

alexmiller16:12:08

;; yields "Value1", a truthy value

alexmiller16: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

shaun-mahood16:12:26

Oooh that is much nicer.

alexmiller16:12:27

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

alexmiller16: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

shaun-mahood16:12:29

I knew there had to be a better way

alexmiller16:12:35

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

alexmiller16:12:56

which will yield either nil (if none) or the value of the first match

shaun-mahood16:12:39

Great, I'll try using the set filter, it's going to make things a lot nicer. Thanks for the help!

polymeris23:12:53

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.

polymeris23:12:09

That seems the functional thing to do.

polymeris23:12:27

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

polymeris23:12:54

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

polymeris23:12:05

Is there no way to pass it a seed?