Created
April 5, 2012 07:15
-
-
Save yayitswei/2308710 to your computer and use it in GitHub Desktop.
leaky-filter
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 leaky-filter [pred l n] | |
(apply | |
concat | |
(filter #(or (some pred %) (< n (count %))) | |
(partition-by nil? l)))) | |
(is (= (leaky-filter [1 nil 2 nil nil nil nil 1 2 3] identity 3) | |
[1 2 nil nil nil nil 1 2 3])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is useful for filtering successful requests from a seq of http requests, where using normal filter would hang if there, say, the server was down.