Filtering Data
The second category of functions in functional programming is filters. A filter function accepts a function that determines which elements should appear in the returned list. There are several ways filtering functions can take shape.
One example is the take function you saw earlier, which discards all items after a target number of elements has been reached. There is also a related function called drop that discards some number of elements from the start of a collection.
But the most general filtering function is aptly named filter.
filter
The filter function accepts a predicate function that checks each element in a collection against a condition and returns a Boolean value. If the predicate returns true, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access