Uniq
constUniq:object
Defined in: Data/Uniq.ts:368
Type Declaration
Section titled “Type Declaration”difference
Section titled “difference”difference: <
A>(other) => (set) =>ReadonlySet<A>
Computes the set difference (set \ other).
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”(set) => ReadonlySet<A>
- union for combining all elements.
- intersection for keeping only common elements.
empty: <
A>() =>ReadonlySet<A>
Creates an empty unique set.
Type Parameters
Section titled “Type Parameters”A
Returns
Section titled “Returns”ReadonlySet<A>
singleton to create a set with one element.
Example
Section titled “Example”filter
Section titled “filter”filter: <
A>(predicate) => (set) =>ReadonlySet<A>
Filters elements of a set by a predicate.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(item) => boolean
Returns
Section titled “Returns”(set) => ReadonlySet<A>
filterMap for filtering and mapping simultaneously.
filterMap
Section titled “filterMap”filterMap: <
A,B>(transform) => (set) =>ReadonlySet<B>
Transforms elements with a function returning Maybe, keeping only Some values.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => Maybe<B>
Returns
Section titled “Returns”(set) => ReadonlySet<B>
from:
object
from.array
Section titled “from.array”array: <
A>(items) =>ReadonlySet<A> =fromArray
Creates a unique set from an array of elements.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”readonly A[]
Returns
Section titled “Returns”ReadonlySet<A>
Example
Section titled “Example”has: <
A>(item) => (set) =>boolean
Returns true when the set contains the given element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(set) => boolean
insert
Section titled “insert”insert: <
A>(item) => (set) =>ReadonlySet<A>
Returns a new set with the element added.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(set) => ReadonlySet<A>
intersection
Section titled “intersection”intersection: <
A>(other) => (set) =>ReadonlySet<A>
Computes the intersection of two sets.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”(set) => ReadonlySet<A>
- union for combining elements from both sets.
- difference for subtracting elements.
is:
object
is.empty
Section titled “is.empty”empty: <
A>(set) =>boolean=isEmpty
Returns true when the set contains zero elements.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”boolean
isNonEmpty to check if a set has elements.
Example
Section titled “Example”is.nonEmpty
Section titled “is.nonEmpty”nonEmpty: <
A>(set) =>set is NonEmptySet<A>=isNonEmpty
Type guard — checks if a set contains at least one element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”set is NonEmptySet<A>
isEmpty to check if a set is empty.
Example
Section titled “Example”is.subsetOf
Section titled “is.subsetOf”subsetOf: <
A>(other) => (set) =>boolean=isSubsetOf
Returns true if set is a subset of other.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”(set) => boolean
Example
Section titled “Example”map: <
A,B>(transform) => (set) =>ReadonlySet<B>
Transforms each element of a set into a new set.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => B
Returns
Section titled “Returns”(set) => ReadonlySet<B>
filterMap for mapping and filtering in a single step.
NonEmpty
Section titled “NonEmpty”NonEmpty:
object=UniqNonEmptyConst
Utilities for working with guaranteed non-empty sets (NonEmptySet).
NonEmpty.from
Section titled “NonEmpty.from”from:
object
NonEmpty.from.set
Section titled “NonEmpty.from.set”set: <
A>(set) =>Maybe<NonEmptySet<A>>
Refines a standard Set to a NonEmptySet, returning Some if size > 0, None otherwise.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”Maybe<NonEmptySet<A>>
Example
Section titled “Example”NonEmpty.map
Section titled “NonEmpty.map”map: <
A,B>(transform) => (set) =>NonEmptySet<B>
Transforms each element of a non-empty set, preserving non-emptiness.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”transform
Section titled “transform”(item) => B
Returns
Section titled “Returns”(set) => NonEmptySet<B>
Example
Section titled “Example”NonEmpty.reduce
Section titled “NonEmpty.reduce”reduce: <
A>(reducer) => (set) =>A
Reduces a non-empty set using the first element as the initial accumulator.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”reducer
Section titled “reducer”(accumulator, item) => A
Returns
Section titled “Returns”(set) => A
Example
Section titled “Example”NonEmpty.singleton
Section titled “NonEmpty.singleton”singleton: <
A>(item) =>NonEmptySet<A>
Creates a NonEmptySet containing a single element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”NonEmptySet<A>
Example
Section titled “Example”NonEmpty.to
Section titled “NonEmpty.to”to:
object
NonEmpty.to.array
Section titled “NonEmpty.to.array”array: <
A>(set) =>NonEmptyArr<A>
Converts a NonEmptySet to a NonEmptyArr.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”NonEmptySet<A>
Returns
Section titled “Returns”NonEmptyArr<A>
Example
Section titled “Example”reduce
Section titled “reduce”reduce: <
A,B>(initial,reducer) => (set) =>B
Reduces elements of a set from an initial value.
Type Parameters
Section titled “Type Parameters”A
B
Parameters
Section titled “Parameters”initial
Section titled “initial”B
reducer
Section titled “reducer”(accumulator, item) => B
Returns
Section titled “Returns”(set) => B
Example
Section titled “Example”remove
Section titled “remove”remove: <
A>(item) => (set) =>ReadonlySet<A>
Returns a new set with the element removed.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(set) => ReadonlySet<A>
insert for adding an element to a set.
singleton
Section titled “singleton”singleton: <
A>(item) =>ReadonlySet<A>
Creates a unique set with a single element.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”ReadonlySet<A>
empty to create an empty set.
Example
Section titled “Example”size: <
A>(set) =>number
Returns the number of elements in the set.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”number
Example
Section titled “Example”to:
object
Converters from unique collections to other data structures.
to.array
Section titled “to.array”array: <
A>(set) => readonlyA[] =toArray
Converts a unique set to a readonly array.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”readonly A[]
Example
Section titled “Example”toggle
Section titled “toggle”toggle: <
A>(item) => (set) =>ReadonlySet<A>
Toggles presence of an element in a set.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”A
Returns
Section titled “Returns”(set) => ReadonlySet<A>
union: <
A>(other) => (set) =>ReadonlySet<A>
Computes the union of two sets.
Type Parameters
Section titled “Type Parameters”A
Parameters
Section titled “Parameters”ReadonlySet<A>
Returns
Section titled “Returns”(set) => ReadonlySet<A>
- intersection for keeping only elements present in both sets.
- difference for subtracting elements.