How to stop iterating a sequence when a condition is met

clojure

Solution

How about this?

(defn find-first [pred col]
  (first (filter pred col)))

Then you can do this as an example:

(find-first #(< % 5) coll)

You should be able to make a predicate that works with a sequence of sequences.

user=> (defn find-first [pred col]
  (first (filter pred col)))
#'user/find-first
user=> (find-first #(> % 10) '(1 5 8 2 15 20 31 5 1))
15

Problem

Other than loop .. recur, what is the best Clojure construct to use so that while traversing a sequence of sequences (sos), the processing can stop if a result is found? Here are the details: I have a lazy sequence returned from clojure-csv, an sos. There is a value at a given position (index) in each sequence within the sos. I keep looking at that position in each sequence until the value is found or the end of sos is reached. If the value is found, I want to stop processing the sos. The only thing I can think of is using a for with when and an into to retain the match, but the sequence processing won't stop, or use filter. However, I believe I can use something better, but I'm stuck as to what that would be. Thanks.

Original source