@metreeca/core - v0.10.0
    Preparing search index...

    Module arrays

    General-purpose array operations.

    Normalising a Value to an Array

    Coerce an optional, single or multi-valued input into an array for uniform iteration:

    import { some } from '@metreeca/core/arrays';

    some(undefined); // []
    some("x"); // ["x"]
    some(["x", "y"]); // ["x", "y"]
    some(new Set(["x", "y"])); // ["x", "y"]

    Retaining Unique Values

    Keep the unique values of a collection, dropping later duplicates:

    import { unique } from '@metreeca/core/arrays';

    unique([1, 1, 2, 3, 3]); // [1, 2, 3]
    unique(new Set([1, 2])); // [1, 2]

    Combining Collections

    Merge several collections into their union, narrow them to their shared intersection, or subtract the later ones from the first, deduplicating in every case:

    import { difference, intersection, union } from '@metreeca/core/arrays';

    union([[1, 2], [2, 3]]); // [1, 2, 3]
    intersection([[1, 2, 3], [2, 3, 4]]); // [2, 3]
    difference([[1, 2, 3], [2, 3, 4]]); // [1]

    Expecting a Cardinality

    Reduce an optional, single or multi-valued input to the number of values a call site expects, failing at the boundary when the input doesn't match:

    import { multiple, optional, required } from '@metreeca/core/arrays';

    required(["x"]); // "x"
    required(["x", "y"]); // TypeError
    optional(undefined); // undefined
    optional(["x", "y"]); // TypeError
    multiple("x"); // ["x"]

    Type Aliases

    Some

    Zero, one, or many values of type T.

    Many

    Zero or more values of type T.

    Functions

    some

    Normalises a Some value into an array.

    unique

    Retains the unique values of a collection.

    union

    Combines collections into their set union.

    intersection

    Reduces collections to their set intersection.

    difference

    Reduces collections to their set difference.

    required

    Reduces a Some value to the single value it must hold.

    optional

    Reduces a Some value to the single value it may hold.

    multiple

    Reduces a Some value to the values it holds.