Skip to content

Instantly share code, notes, and snippets.

@odf
Created November 1, 2011 08:20
Show Gist options
  • Save odf/1330143 to your computer and use it in GitHub Desktop.
Save odf/1330143 to your computer and use it in GitHub Desktop.
(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