first
fn first<T>(Vec<T> xs) -> Option<T> Import
Source: use collections::vec::{first}; src/collections/vec.hy Returns the first element, or None when xs is empty.
Parameters#
| Name | Type |
|---|---|
xs | Vec<T> |
Returns#
Option<T>
Examples#
use collections::vec::{first};
use tests::assert;
let xs: Vec<string> = ["a", "b"];
assert!((first(xs) ?? "") == "a");
let none: Vec<int> = Vec::new();
assert!(first(none).is_none());
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.filter: Returns the elements for whichpredistrue, in order.last: Returns the last element, orNonewhenxsis empty.