Array.filter3kaya
Filter a list according to a predicate.
Usage
[a] filter( Bool(a) p, [a] xs )
Arguments
p The predicate to test against
xs The array to filter
Overview
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)
Releases
4 releases since Debian 5.0 (Lenny); the text changed 3 times.