Searching v0.1.0

Source
Linear queries over a slice in no particular order: whether it holds a value, where, and how many.

Contains<T>

pub func Contains<T>(items: T[..], value: T) -> bool

Whether any element of items equals value. items is borrowed and read; value is read by value. An empty slice contains nothing, so this is false. Cannot fail. Runs in time proportional to the length, stopping at the first match, and allocates nothing.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
valueTthe value to look for

Returns: whether any element equals value

Count<T>

pub func Count<T>(items: T[..], value: T) -> uint

How many elements of items equal value. items is borrowed and read; value is read by value. An empty slice gives zero. Cannot fail. Runs in time proportional to the length and allocates nothing.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
valueTthe value to look for

Returns: how many elements equal value

IndexOf<T>

pub func IndexOf<T>(items: T[..], value: T) -> uint?

The index of the first element of items equal to value. items is borrowed and read; value is read by value. Reports none when no element matches, including for an empty slice. Cannot fail. Runs in time proportional to the length, stopping at the first match, and allocates nothing.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
valueTthe value to look for

Returns: the first index holding value, or none

LastIndexOf<T>

pub func LastIndexOf<T>(items: T[..], value: T) -> uint?

The index of the last element of items equal to value. items is borrowed and read; value is read by value. Reports none when no element matches. Cannot fail. Runs in time proportional to the length, stopping at the first match from the end, and allocates nothing.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
valueTthe value to look for

Returns: the last index holding value, or none

IndexWhere<T>

pub func IndexWhere<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> uint?

The index of the first element of items that predicate accepts. items is borrowed and read; predicate is called once per element until it accepts one. Reports none when it accepts none. Cannot fail. Runs in time proportional to the length and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: the first index whose element satisfies predicate, or none

LastIndexWhere<T>

pub func LastIndexWhere<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> uint?

The index of the last element of items that predicate accepts. items is borrowed and read; predicate is called once per element from the end until it accepts one. Reports none when it accepts none. Cannot fail. Runs in time proportional to the length and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: the last index whose element satisfies predicate, or none

CountWhere<T>

pub func CountWhere<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> uint

How many elements of items the predicate accepts. items is borrowed and read; predicate is called once per element. An empty slice gives zero. Cannot fail. Runs in time proportional to the length and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: how many elements satisfy predicate

AllOf<T>

pub func AllOf<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> bool

Whether predicate accepts every element of items. items is borrowed and read. An empty slice satisfies this, as it satisfies every universal claim: there is no element that fails. Cannot fail. Runs in time proportional to the length, stopping at the first rejection, and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: whether every element satisfies predicate; true for an empty sequence

AnyOf<T>

pub func AnyOf<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> bool

Whether predicate accepts at least one element of items. items is borrowed and read. An empty slice does not satisfy this: there is no element that passes. Cannot fail. Runs in time proportional to the length, stopping at the first acceptance, and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: whether any element satisfies predicate; false for an empty sequence

NoneOf<T>

pub func NoneOf<T>(
    items: T[..],
    predicate: func(T) -> bool
) -> bool

Whether predicate accepts no element of items. items is borrowed and read. An empty slice satisfies this, for the same reason it satisfies AllOf. Cannot fail. Runs in time proportional to the length, stopping at the first acceptance, and allocates nothing beyond whatever predicate does.

Source

Type parameters

NameDescription
Tthe element type

Parameters

NameTypeDescription
itemsT[..]the sequence to work on
predicatefunc(T) -> boolthe test each element is put to

Returns: whether no element satisfies predicate; true for an empty sequence