Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Created March 20, 2010 13:54
Show Gist options
  • Save pervognsen/338682 to your computer and use it in GitHub Desktop.
Save pervognsen/338682 to your computer and use it in GitHub Desktop.
;; general utility. like reduce but gives a list of all intermediate results.
(defn scan [f val coll]
(if-let [s (seq coll)]
(lazy-seq (cons val (scan f (f val (first s)) (rest s))))
[val]))
(defn indexed-pred [pred coll]
(map #(if (pred %1) [%2 %1] [%1]) coll (scan + 0 (map #(if (pred %) 1 0) coll))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment