Function in collections::vec coil-stdlib

contains

fn contains(Vec<int> xs, int needle) -> bool
fn contains(Vec<string> xs, string needle) -> bool
Import
use collections::vec::{contains};
Source: src/collections/vec.hy

Returns true when needle is in xs. There is an int and a string version.

fn contains(Vec<int> xs, int needle) -> bool#

Parameters#

NameType
xsVec<int>
needleint

Returns#

bool

Contracts#

Checked according to --contracts (see Contracts).

ensures !result || xs.len() > 0

fn contains(Vec<string> xs, string needle) -> bool#

Returns true when needle is in xs.

Parameters#

NameType
xsVec<string>
needlestring

Returns#

bool

Contracts#

Checked according to --contracts (see Contracts).

ensures !result || xs.len() > 0

Examples#

use collections::vec::{contains};
use tests::assert;
let xs: Vec<int> = [3, 1, 4];
assert!(contains(xs, 4));
let names: Vec<string> = ["ada", "alan"];
assert!(!contains(names, "grace"));

See also#

  • int
  • string
  • fold_int: The same as fold; kept for older code.
  • 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.
↑ ↓ navigate ↵ open