Function in collections::vec coil-stdlib

first

fn first<T>(Vec<T> xs) -> Option<T>
Import
use collections::vec::{first};
Source: src/collections/vec.hy

Returns the first element, or None when xs is empty.

Parameters#

NameType
xsVec<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 as fold; kept for older code.
  • contains: Returns true when needle is in xs.
  • index_of: Returns the index of the first needle in xs, or -1.
  • binary_search: Finds needle in the ascending vector xs by halving, and returns an index holding it.
  • dedup: Returns xs with runs of equal neighbours collapsed to one value.
  • map: Returns a new vector with mapper applied to each element, in order.
  • filter: Returns the elements for which pred is true, in order.
  • last: Returns the last element, or None when xs is empty.
↑ ↓ navigate ↵ open