Last active
December 31, 2016 05:32
-
-
Save craftybones/399dfcd2cf074e1fcb4d535f876a92fe 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
(defn take-while-adjacent | |
[f coll] | |
(lazy-seq | |
(when-let [s (seq coll)] | |
(if (f (first s) (second s)) | |
(cons (first s) (take-while-adjacent f (rest s))) | |
(cons (first s) nil))))) | |
; => (take-while-adjacent not= [1 2 3 3]) | |
; (1 2 3) | |
; => (take-while-adjacent = [1 1 1 2]) | |
; (1 1 1) | |
; => (take-while-adjacent square-of [2 4 16 256 100]) | |
; (2 4 16 256) | |
; => (take-while-adjacent subset-of [1 [1] [[1] [1 2]] [4]]) | |
; (1 [1] [[1] [1 2]]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment