racket Higher Order Functions Filter


Example

filter returns a list of each item in the given list for which the given predicate returns a non-#f value.

;; Get only even numbers in a list
> (filter even? '(1 2 3 4))
'(2 4)

;; Get all square numbers from 1 to 100
> (filter (lambda (n) (integer? (sqrt n))) (range 1 100))
'(1 4 9 16 25 36 49 64 81)