collections

stdlib::rss::collections

Generic array and map helpers.

Import

use stdlib::rss::collections;

Functions

FunctionDescription
index_ofReturns the first index of a value in an array, or -1 when it is absent.
containsReturns whether an array contains a value.
reverseReturns a reversed copy of an array.
dedupReturns an array with duplicate values removed.
hasReturns whether a map contains a key.
get_orReturns a map value or a fallback when the key is absent.
valuesReturns the values from a map as an array.
entriesReturns the [key, value] pairs from a map as an array.
mergeMerges two maps, preferring values from rhs for duplicate keys.

Function details

index_of

pub fn index_of<T>(values: [T], needle: T) -> int

Returns the first index of a value in an array, or -1 when it is absent.

contains

pub fn contains<T>(values: [T], needle: T) -> bool

Returns whether an array contains a value.

reverse

pub fn reverse<T>(values: [T]) -> [T]

Returns a reversed copy of an array.

dedup

pub fn dedup<T>(values: [T]) -> [T]

Returns an array with duplicate values removed.

has

pub fn has<K, V>(map: map<V>, key: K) -> bool

Returns whether a map contains a key.

get_or

pub fn get_or<K, V>(map: map<V>, key: K, fallback: V) -> V

Returns a map value or a fallback when the key is absent.

values

pub fn values<V>(map: map<V>) -> [V]

Returns the values from a map as an array.

entries

pub fn entries<K, V>(map: map<V>) -> [[K, V]]

Returns the [key, value] pairs from a map as an array.

merge

pub fn merge<V>(lhs: map<V>, rhs: map<V>) -> map<V>

Merges two maps, preferring values from rhs for duplicate keys.