Skip to content

Instantly share code, notes, and snippets.

@odf odf/reduce-true.clj
Created Nov 1, 2011

Embed
What would you like to do?
(defn tails [s]
"The sequence of sequences starting at each position in the given sequence 's'."
(lazy-seq (when-let [s (seq s)]
(cons s (tails (rest s))))))
(defn reduce-true [f val coll]
"A short-circuiting version of 'reduce'. Stops evaluation when the
accumulated value is logically false."
(let [v (->> (reductions f val coll)
(tails)
(take-while first)
(last))]
(if (empty? (rest v)) (first v))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.