filter
fn filter<T>(Vec<T> xs, T -> bool pred) -> Vec<T> Import
Source: use collections::vec::{filter}; src/collections/vec.hy Returns the elements for which pred is true, in order.
Parameters#
| Name | Type |
|---|---|
xs | Vec<T> |
pred | T -> bool |
Returns#
Vec<T>
Examples#
use collections::vec::{filter};
use tests::assert;
let xs: Vec<int> = [1, 2, 3, 4];
let even = filter(xs, fn (int x) => x % 2 == 0);
assert!(even.len() == 2 && even[0] == 2);
See also#
fold_int: The same asfold; kept for older code.contains: Returnstruewhenneedleis inxs.index_of: Returns the index of the firstneedleinxs, or-1.binary_search: Findsneedlein the ascending vectorxsby halving, and returns an index holding it.dedup: Returnsxswith runs of equal neighbours collapsed to one value.map: Returns a new vector withmapperapplied to each element, in order.first: Returns the first element, orNonewhenxsis empty.last: Returns the last element, orNonewhenxsis empty.