filterv eagerly applies a predicate to any seqable collection and returns the retained elements as a persistent vector, preserving input order. Use it when the result should be a vector; choose filter when laziness or output type matters more. section 12.9
Its contract is straightforward:
- pred is a predicate; each item is retained when (pred item) is truthy. section 12.9
- coll may be any seqable collection; nil is treated as empty. section 12.9
- The result is a persistent vector, and eager evaluation loads it into memory. section 12.9
- Incorrect predicate arity throws ArityException; a non-function predicate throws ClassCastException; a non-seqable collection throws IllegalArgumentException. section 12.9
- filterv has no transducer arity and runs in O(n) time and space. section 12.9
Filtering a range
(filterv odd? (range 8)) ;; [1 3 5 7] A practical use filters completed asynchronous channels from the remaining channel vector: (filterv #(not= channel %) channels)
