filter
The filter
function is a commonly-used higher-order function
s.
It takes a function as an argument.
The filter
function works as its name implies.
It filters out values in a sequence that don’t meet the given condition.
To perform this filtering, filter
takes a function and a sequence for its arguments.
The function given to the filter
must return a truthy value, and is called a predicate function.
(see Truthiness
)
The syntax is: (filter pred coll)
Let’s see the examples:
We can use an anonymous function
for filtering.
The next example defines a flower list as a map (data structure) with simple keys and colors as values.
From this map, the code below selects yellows or pinks.
We can also use the function we defined for filtering. The third example selects palindromic numbers between 1000 and 4999. (see palindrome: http://en.wikipedia.org/wiki/Palindromic_number)
ClojureDocs
Introduction to Clojure, filter and remove
http://clojure-doc.org/articles/tutorials/introduction.html#filter-and-remove
Clojure from the ground up: sequences, Subsequences
http://aphyr.com/posts/304-clojure-from-the-ground-up-sequences
Clojure for the Brave and True, Core Functions in Depth
http://www.braveclojure.com/core-functions-in-depth/#5__FWPD
GetClojure