Created
March 20, 2010 13:54
-
-
Save pervognsen/338682 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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