Class Set

Additional static members for the native Set class.

Does not extend the native Set class.

Constructors

Methods

  • Add the provided element to the set.

    Type Parameters

    • T

    Parameters

    • set: Set<T>

      the set to mutate

    • element: T

      the element to add

    • comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns Set<T>

    the mutated set

  • Delete the provided element from the set.

    Type Parameters

    • T

    Parameters

    • set: Set<T>

      the set to mutate

    • element: T

      the element to delete

    • comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Was the set mutated?

  • Return the difference (nonimplication) of two sets: the set of elements in a, but not in b.

    Type Parameters

    • T
    • U

    Parameters

    • a: ReadonlySet<T>

      the first set

    • b: ReadonlySet<U>

      the second set

    • Optional comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns Set<T>

    a new Set containing the elements present only in a

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in a

    Typeparam

    U - the type of elements in b

  • Return a new set with elements that pass the provided predicate function.

    Type Parameters

    • T

    Parameters

    • set: Set<T>

      the set to filter

    • predicate: ((element, index, set) => boolean)

      function to test each element of the set

        • (element, index, set): boolean
        • Parameters

          • element: T
          • index: T
          • set: Set<T>

          Returns boolean

    • this_arg: unknown = null

      object to use as this when executing predicate

    Returns Set<T>

    a new set with the elements that pass the test; if no elements pass, an empty set is returned

    See

    https://github.com/tc39/proposal-collection-methods

    Typeparam

    T - the type of elements in the set

  • Return a value found in the set that satisfies the predicate, or null if none is found.

    Type Parameters

    • T

    Parameters

    • set: Set<T>

      the set to search

    • predicate: ((element, index, set) => boolean)

      function to test each element of the set

        • (element, index, set): boolean
        • Parameters

          • element: T
          • index: T
          • set: Set<T>

          Returns boolean

    • this_arg: unknown = null

      object to use as this when executing predicate

    Returns null | T

    the item found, or null if none is found

    See

    https://github.com/tc39/proposal-collection-methods

    Typeparam

    T - the type of elements in the set

  • Return whether the provided element exists in the set.

    Type Parameters

    • T

    Parameters

    • set: ReadonlySet<T>

      the set to check

    • element: T

      the element to check

    • comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Does the set have the given element?

  • Return the intersection (conjunction) of two sets: the set of elements that are in both sets.

    Type Parameters

    • T
    • U

    Parameters

    • a: ReadonlySet<T>

      the first set

    • b: ReadonlySet<U>

      the second set

    • Optional comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns Set<T & U>

    a new Set containing the elements present only in both a and b

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in a

    Typeparam

    U - the type of elements in b

  • Test whether two sets have “the same” elements.

    Similar to xjs_Array.is, but for sets, the order of elements is not important.

    Type Parameters

    • T

    Parameters

    • a: ReadonlySet<T>

      the first set

    • b: ReadonlySet<T>

      the second set

    • Optional predicate: ((x, y) => boolean)

      check the “sameness” of corresponding elements of a and b

        • (x, y): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Are corresponding elements the same, i.e. replaceable?

    Typeparam

    T - the type of elements in the sets

  • Return whether a is a subset of b: whether all elements of a are in b.

    Note that if a is an empty set, this method returns true.

    Type Parameters

    • U
    • T

    Parameters

    • a: ReadonlySet<T>

      the smaller set

    • b: ReadonlySet<U>

      the larger set

    • Optional predicate: ((x, y) => boolean)

      check the “sameness” of corresponding elements of a and b

        • (x, y): boolean
        • Parameters

          Returns boolean

    Returns boolean

    Is a a subset of b?

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in a

    Typeparam

    U - the type of elements in b

  • xjs_Set.isSubsetOf, but with the parameters switched.

    Type Parameters

    • T
    • U

    Parameters

    • a: ReadonlySet<T>

      the larger set

    • b: ReadonlySet<U>

      the smaller set

    • Optional predicate: ((x, y) => boolean)

      check the “sameness” of corresponding elements of a and b

        • (x, y): boolean
        • Parameters

          Returns boolean

    Returns boolean

    exactly xjs.Set.isSubsetOf(b, a, predicate)

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in a

    Typeparam

    U - the type of elements in b

  • Return a new Set with the results of calling a provided function on every element in the given Set.

    Type Parameters

    • T
    • U

    Parameters

    • set: Set<T>

      the set to map

    • callback: ((element, index, set) => U)

      the function to call on each element of the set

        • (element, index, set): U
        • Parameters

          • element: T
          • index: T
          • set: Set<T>

          Returns U

    • this_arg: unknown = null

      object to use as this when executing callback

    Returns Set<U>

    a new Set with transformed elements obtained from callback

    See

    https://github.com/tc39/proposal-collection-methods

    Typeparam

    T - the type of elements in the set

    Typeparam

    U - the type of new elements returned by the callback

  • Return the symmetric difference (exclusive disjunction) of two sets: the set of elements either in one set, or in the other, but not both.

    Equivalent to:

    • difference( union(a,b) , intersection(a,b) )
    • union( difference(a,b) , difference(b,a) )

    Type Parameters

    • T
    • U

    Parameters

    • a: ReadonlySet<T>

      the first set

    • b: ReadonlySet<U>

      the second set

    • Optional comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns Set<T | U>

    a new Set containing the elements present only in a or only in b, but not both

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in a

    Typeparam

    U - the type of elements in b

  • Return the union (disjunction) of two sets: the set of elements that are in either set (or both sets).

    Type Parameters

    • T
    • U

    Parameters

    • a: ReadonlySet<T>

      the first set

    • b: ReadonlySet<U>

      the second set

    • Optional comparator: ((a, b) => boolean)

      a comparator function

        • (a, b): boolean
        • Parameters

          Returns boolean

    Returns Set<T | U>

    a new Set containing the elements present in either a or b (or both)

    See

    https://github.com/tc39/proposal-set-methods

    Typeparam

    T - the type of elements in the a

    Typeparam

    U - the type of elements in the b