Skip to content

array

Helpers for slices and Vecs that the standard library does not provide.

Inputs are borrowed slices and results are new Vecs: nothing is mutated. Membership-based helpers require Eq + Hash.

Cargo feature array (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features array

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["array"] }

Import path: helpers4::array.

ItemWhat it does
cartesian_productReturns every pair (x, y) with x from a and y from b, in row-major order.
count_byCounts the elements of items per key returned by key.
differenceReturns the elements of a that are not in b, in a’s order.
duplicatesReturns the elements that appear more than once in items, each one once, in the order they first appear.
equals_unorderedReturns true when a and b hold the same elements the same number of times, in any order.
group_byGroups the elements of items by the key returned by key.
interleaveAlternates the elements of a and b, starting with a; the leftover of the longer slice goes at the end.
intersectionReturns the elements of a that also appear in b, in a’s order.
intersectsReturns true when a and b share at least one element.
key_byIndexes the elements of items by the key returned by key.
symmetric_differenceReturns the elements present in exactly one of a and b.
uniqueRemoves duplicate values, keeping the first occurrence of each and the original order.
unique_byRemoves elements whose key was already seen, keeping the first of each key in order.