OpenMusic Reference
list-filter
list-filter
(lists module) -- Filters elements from a list using the predicate test .
Syntax
list-filter test list mode
Inputs
name | data type(s) | comments |
---|---|---|
test | a symbol or function name or lambda function | The predicate to apply. Defaults to numberp |
list | a list | the list to filter |
mode | menu | two options: pass and reject |
Output
output | data type(s) | comments |
---|---|---|
first | a list |
Description
list-filter applies the function test to each element of list . test may be any predicate, either a function name or a patch in lambda mode. If mode is set to reject then elements which return t when passed to test are rejected. If mode is set to pass then only those elements are kept.
![]() |
list-filter only operates on the first level of nesting. Sublists are passed in their entirety to test . To process sublists, use table-filter
—|—
Examples
Filtering a list for numeric values
Here, the list is tested using numberp , a predicate which returns t only when its object is a number. The function is in pass mode, so the output will be:
? OM->(1 2 3)
Setting the mode to reject passes only those elements failing the test numberp :
? OM->(a b c)
Filtering a list using a lambda function
Here is an example of using a lambda function. The function om> is passed, in lambda mode, with the second input set to 2. As usual with lambda functions, the values will be passed to its first input.
All the elements of the list are passed, one by one, to om> . Since mode is pass , only elements of the list greater than 2 will be passed:
? OM->(3 4 5 6)
Prev | Home | Next |
---|---|---|
list-explode | Up | list-max |