Fork me on GitHub
#beginners
<
2017-06-17
>
victora00:06:56

What's the canonical way to find an element in a collection which satisfies a condition?

victora00:06:07

Like find the first element in a list which is greater than 5, or all of them for that matter

victora00:06:11

reduce, right?

dees00:06:59

you can definitely do just about anything with reduce

dees00:06:51

i'm used to ruby where there are built in things like detect and any? which are more task-specific to things like "give me the first matching" or "does at least one match?" or "do all elements match" or "drop elements that don't match" etc.

dees00:06:12

but those are all literally just sugar around using reduce effectively

victora01:06:28

I know I can, but I also need to know the canonical way to do it

dees01:06:43

not sure about that. i would presume reduce is a good way to go about it

shaun-mahood01:06:07

@victora: filter is the function to use for that, it will return only those items that satisfy your conditions

noisesmith03:06:06

@victora the normal way to do that is (first (filter pred? ...)) - it's a perrenial surprise for people to find out there isn't something more specialized