contains
fn contains(Vec<int> xs, int needle) -> boolfn contains(Vec<string> xs, string needle) -> bool Import
Source: use collections::vec::{contains}; 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#
| Name | Type |
|---|---|
xs | Vec<int> |
needle | int |
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#
| Name | Type |
|---|---|
xs | Vec<string> |
needle | string |
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#
intstringfold_int: The same asfold; kept for older code.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.