DWiki /
filter
Difference (last change) (no other diffs, normal page display)
Changed: 1c1,11
Describe the new page here. |
A function that takes a collection, a predicate and return another collection of same kind, containg all the elements satisfying the predicate. Usually used with lists, but may be used with any kind of collection. Using /DeimosTemplateLibrary: instance TArrays(int) arrays; const int[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; boolean even(int i) { return i % 2 == 0;}; int[] evens = arrays.filter(numbers, even); (From DWiki) |
A function that takes a collection, a predicate and return another collection of same kind, containg all the elements satisfying the predicate. Usually used with lists, but may be used with any kind of collection.
Using /DeimosTemplateLibrary:
instance TArrays(int) arrays; const int[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; boolean even(int i) { return i % 2 == 0;}; int[] evens = arrays.filter(numbers, even);
(From DWiki)