-
-
Save sw1nn/4684523a7063dc0fb08a to your computer and use it in GitHub Desktop.
partition-by when pred is true
This file contains 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 parter [pred] | |
(let [v (atom 0)] | |
(fn [x] | |
(if (pred x) (swap! v inc) @v)))) | |
(partition-by (parter identity) [ false false true false true ]) | |
;=> ((false false) (true false) (true)) | |
; cf. | |
(partition-by identity [ false false true false true ]) | |
;=> ((false false) (true) (false) (true)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment