General-purpose array operations.
Normalising a Value to an Array
Coerce an optional or single-or-many value into an array for uniform iteration:
import { some } from '@metreeca/core/arrays';const tags = some(input); // undefined -> [], "x" -> ["x"], ["x", "y"] -> ["x", "y"] Copy
import { some } from '@metreeca/core/arrays';const tags = some(input); // undefined -> [], "x" -> ["x"], ["x", "y"] -> ["x", "y"]
Retaining Unique Values
Keep the unique values of an array, dropping later duplicates:
import { unique } from '@metreeca/core/arrays';unique([1, 1, 2, 3, 3]); // [1, 2, 3] Copy
import { unique } from '@metreeca/core/arrays';unique([1, 1, 2, 3, 3]); // [1, 2, 3]
Combining Arrays as Sets
Merge several arrays into their union or narrow them to their shared intersection, deduplicating either way:
import { intersection, union } from '@metreeca/core/arrays';union([[1, 2], [2, 3]]); // [1, 2, 3]intersection([[1, 2, 3], [2, 3, 4]]); // [2, 3] Copy
import { intersection, union } from '@metreeca/core/arrays';union([[1, 2], [2, 3]]); // [1, 2, 3]intersection([[1, 2, 3], [2, 3, 4]]); // [2, 3]
Zero, one, or many values of type T.
T
Normalises a Some value into an array.
Retains the unique values of an array.
Combines arrays into their set union.
Reduces arrays to their set intersection.
General-purpose array operations.
Normalising a Value to an Array
Coerce an optional or single-or-many value into an array for uniform iteration:
Retaining Unique Values
Keep the unique values of an array, dropping later duplicates:
Combining Arrays as Sets
Merge several arrays into their union or narrow them to their shared intersection, deduplicating either way: