map
fn map<T, U>(Vec<T> xs, T -> U mapper) -> Vec<U> Import
Source: use collections::vec::{map}; src/collections/vec.hy Returns a new vector with mapper applied to each element, in order.
Parameters#
| Name | Type |
|---|---|
xs | Vec<T> |
mapper | T -> U |
Returns#
Vec<U>
Examples#
use collections::vec::{map};
use string::{format};
use tests::assert;
let xs: Vec<int> = [1, 2, 3];
let squares = map(xs, fn (int x) => x * x);
assert!(squares[2] == 9);
let labels = map(xs, fn (int x) => format("#%i", x));
assert!(labels[0] == "#1");
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.filter: Returns the elements for whichpredistrue, in order.first: Returns the first element, orNonewhenxsis empty.last: Returns the last element, orNonewhenxsis empty.