Skip to content

clojure.core/filter

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 11 Runnable: 6
([pred] [pred coll])

Returns a lazy sequence of the items in coll for which (pred item) returns logical true. pred must be free of side-effects. Returns a transducer when no collection is provided.

Examples

by nipra on . May have evaluation errors.
by bsvingen on
by Art-B on . May have evaluation errors.
by puppybits on
by sleyzerzon on
by sleyzerzon on . May have evaluation errors.
by mdubakov on . May have evaluation errors.
by st-keller on . May have evaluation errors.
by ibercode on
by codxse on
by tmountain on

Note by brunchboy

Although the documentation states that the predicate must be free of side effects, it would be more accurate to say that you should not rely on filter to induce side effects that may be caused by the predicate, nor on the timing of when the predicate will be evaluated, because of the lazy and chunked nature of filter.

Note by mattiasw2

Note that filtering a map will not create a map. If you want to do a lookup on the result, you need to surround the call to filter with (into {} (filter ...))

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.