(filter pred)
(filter pred coll)
Returns a lazy sequence of the items in coll for which
(pred item) returns true. pred must be free of side-effects.
Returns a transducer when no collection is provided.
Example
(do
["Exclude languages with single character names"]
(filter
(fn* [p1__18668#] (> (count p1__18668#) 1))
["Java" "Lisp" "Fortran" "C" "D" "C++"]))
Source
(defn
filter
"Returns a lazy sequence of the items in coll for which\n (pred item) returns true. pred must be free of side-effects.\n Returns a transducer when no collection is provided."
([pred]
(fn
[rf]
(fn
([] (rf))
([result] (rf result))
([result input] (if (pred input) (rf result input) result)))))
([pred coll]
(lazy-seq
(when-let
[s (seq coll)]
(if
(chunked-seq? s)
(let
[c (chunk-first s) size (count c) b (chunk-buffer size)]
(dotimes
[i size]
(when (pred (-nth c i)) (chunk-append b (-nth c i))))
(chunk-cons (chunk b) (filter pred (chunk-rest s))))
(let
[f (first s) r (rest s)]
(if (pred f) (cons f (filter pred r)) (filter pred r))))))))