Array::filter(3) Filter a list according to a predicate.

SYNOPSIS

[a] filter( Bool(a) p, [a] xs )

ARGUMENTS

p The predicate to test against

xs The array to filter

DESCRIPTION

Each element of xs is tested against the predicate p

The returned list contains those elements of xs for which the predicate is true. The predicate function may of course be partially applied for ease of programming.


 Bool isDiv(Int d,Int a) {
     return (a%d==0);
 }
 
 Void main() {
     ints = [1,2,3,4,5,6,7,8];
     odds = filter(isDiv@(3),ints);
     // odds = [3,6];
 }

Naturally, all(p,filter(p,xs)) == any(p,xs)

AUTHORS

Kaya standard library by Edwin Brady, Chris Morris and others ([email protected]). For further information see http://kayalang.org/

LICENSE

The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (version 2.1 or any later version) as published by the Free Software Foundation.

RELATED

Array.any(3kaya)

Array.all(3kaya)