Skip to content

Instantly share code, notes, and snippets.

@yayitswei
Created April 5, 2012 07:15
Show Gist options
  • Save yayitswei/2308710 to your computer and use it in GitHub Desktop.
Save yayitswei/2308710 to your computer and use it in GitHub Desktop.
leaky-filter
(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]))
@yayitswei
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment