Options
All
  • Public
  • Public/Protected
  • All
Menu

Class XSet<T>

An extension of Set that provides methods supporting common iterator operations such as map and filter, as well as common set operations such as union and isSubsetOf.

Type parameters

  • T

Hierarchy

  • XSet

Implements

  • Set<T>

Index

Constructors

constructor

  • new XSet(values?: Iterable<T> | null): XSet
  • Parameters

    • Optional values: Iterable<T> | null

    Returns XSet

Properties

Private set

set: Set<T>

Internally, XSet is implemented using composition, as opposed to inheritance.

Native Accessors

__@toStringTag

  • get __@toStringTag(): string
  • category

    Native

    Returns string

size

  • get size(): number
  • The number of elements in the set.

    category

    Native

    Returns number

Iterator Methods

every

  • every(callbackfn: function, thisArg?: any): boolean
  • Determines whether the provided callback function returns true for every element of the set.

    Returns true if the set is empty.

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): boolean
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns boolean

    • Optional thisArg: any

    Returns boolean

filter

  • filter<U>(callbackfn: function, thisArg?: any): XSet<U>
  • filter<U>(callbackfn: function, thisArg?: any): XSet<T & U>
  • filter(callbackfn: function, thisArg?: any): XSet<T>
  • Returns the elements of the set that meet the condition specified in the provided callback function.

    Type parameters

    • U: T

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): value is U
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns value is U

    • Optional thisArg: any

    Returns XSet<U>

  • Returns the elements of the set that meet the condition specified in the provided callback function.

    category

    Iterator

    Type parameters

    • U

    Parameters

    • callbackfn: function
        • (value: any, value2: T, set: XSet<T>): value is U
        • Parameters

          • value: any
          • value2: T
          • set: XSet<T>

          Returns value is U

    • Optional thisArg: any

    Returns XSet<T & U>

  • Returns the elements of the set that meet the condition specified in the provided callback function.

    category

    Iterator

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): boolean
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns boolean

    • Optional thisArg: any

    Returns XSet<T>

find

  • find<U>(predicate: function, thisArg?: any): U | undefined
  • find<U>(predicate: function, thisArg?: any): T & U | undefined
  • find(predicate: function, thisArg?: any): T | undefined
  • Returns the first element in this set (in insertion order) that satisfies the provided predicate. Returns undefined if none of the elements satisfy the predicate.

    Type parameters

    • U: T

    Parameters

    • predicate: function
        • (value: T, value2: T, set: XSet<T>): value is U
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns value is U

    • Optional thisArg: any

    Returns U | undefined

  • Returns the first element in this set (in insertion order) that satisfies the provided predicate. Returns undefined if none of the elements satisfy the predicate.

    category

    Iterator

    Type parameters

    • U

    Parameters

    • predicate: function
        • (value: any, value2: T, set: XSet<T>): value is U
        • Parameters

          • value: any
          • value2: T
          • set: XSet<T>

          Returns value is U

    • Optional thisArg: any

    Returns T & U | undefined

  • Returns the first element in this set (in insertion order) that satisfies the provided predicate. Returns undefined if none of the elements satisfy the predicate.

    category

    Iterator

    Parameters

    • predicate: function
        • (value: T, value2: T, set: XSet<T>): boolean
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns boolean

    • Optional thisArg: any

    Returns T | undefined

flat

  • Returns a union of this set's sets. Requires this to be a set of sets.

    Type parameters

    • U

    Parameters

    • this: XSet<Set<U>>

    Returns XSet<U>

map

  • map<U>(callbackfn: function, thisArg?: any): XSet<U>
  • Calls the provided callback function on each element of the set, and returns a set that contains the results.

    Type parameters

    • U

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): U
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns U

    • Optional thisArg: any

    Returns XSet<U>

reduce

  • reduce<U>(callbackfn: function, initialValue: U): U
  • reduce(callbackfn: function): T
  • Calls the provided callback function for all the elements in the set. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    The elements are iterated over in insertion order.

    Type parameters

    • U

    Parameters

    • callbackfn: function
        • (acc: U, value: T, value2: T, set: XSet<T>): U
        • Parameters

          • acc: U
          • value: T
          • value2: T
          • set: XSet<T>

          Returns U

    • initialValue: U

    Returns U

  • Calls the provided callback function for all the elements in the set. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    The elements are iterated over in insertion order.

    category

    Iterator

    Parameters

    • callbackfn: function
        • (acc: T, value: T, value2: T, set: XSet<T>): T
        • Parameters

          • acc: T
          • value: T
          • value2: T
          • set: XSet<T>

          Returns T

    Returns T

some

  • some(callbackfn: function, thisArg?: any): boolean
  • Determines whether the provided callback function returns true for any element of the set.

    Returns false if the set is empty.

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): boolean
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns boolean

    • Optional thisArg: any

    Returns boolean

Native Methods

__@iterator

  • __@iterator(): IterableIterator<T>
  • Iterates over elements in the set, in insertion order.

    Returns IterableIterator<T>

add

  • add(value: T): this
  • Parameters

    • value: T

    Returns this

clear

  • clear(): void
  • Removes all elements from the set.

    Returns void

delete

  • delete(value: T): boolean
  • If the provided value is in the set, deletes the value and returns true. Otherwise, returns false.

    Parameters

    • value: T

    Returns boolean

entries

  • entries(): IterableIterator<[T, T]>
  • Returns an iterable of [v,v] pairs for every element v in the set, in insertion order.

    Returns IterableIterator<[T, T]>

forEach

  • forEach(callbackfn: function, thisArg?: any): void
  • Calls the provided callback once for each element in the set, in insertion order.

    Parameters

    • callbackfn: function
        • (value: T, value2: T, set: XSet<T>): void
        • Parameters

          • value: T
          • value2: T
          • set: XSet<T>

          Returns void

    • Optional thisArg: any

    Returns void

has

  • has(value: T): boolean
  • Determines if the set has the provided value.

    Parameters

    • value: T

    Returns boolean

keys

  • keys(): IterableIterator<T>
  • Despite its name, returns an iterable of the values (i.e., elements) in the set, in insertion order.

    Returns IterableIterator<T>

values

  • values(): IterableIterator<T>
  • Returns an iterable of elements in the set, in insertion order.

    Returns IterableIterator<T>

Other Methods

addAll

  • addAll(values: Iterable<T>): this
  • Adds all the elements yielded by the provided iterable to this set.

    Parameters

    • values: Iterable<T>

    Returns this

clone

  • Returns a new set containing all this set's elements.

    Returns XSet<T>

deleteAll

  • deleteAll(values: Iterable<T>): void
  • Deletes all the elements yielded by the provided iterable from this set.

    Parameters

    • values: Iterable<T>

    Returns void

toArray

  • toArray(): T[]
  • Returns an array of all the elements in this set, in insertion order.

    Returns T[]

Set Theory Methods

cartesianProduct

  • cartesianProduct<U>(other: Set<U>): XSet<[T, U]>
  • Returns the set of all [t, u] for each t in this and each u in other.

    Type parameters

    • U

    Parameters

    • other: Set<U>

    Returns XSet<[T, U]>

difference

  • difference(other: Set<any>): XSet<T>
  • Returns a set of all the elements that are in this but not in other.

    Parameters

    • other: Set<any>

    Returns XSet<T>

equals

  • equals(other: Set<any>): boolean
  • Determines if this set has exactly the same elements as the provided set.

    Parameters

    • other: Set<any>

    Returns boolean

intersection

  • intersection<U>(other: Set<U>): XSet<T & U>
  • Returns a set containing all the elements that are both in this and other.

    Type parameters

    • U

    Parameters

    • other: Set<U>

    Returns XSet<T & U>

isDisjointFrom

  • isDisjointFrom(other: Set<any>): boolean
  • Determines if there are zero elements that are both in this set and the provided set.

    Parameters

    • other: Set<any>

    Returns boolean

isProperSubsetOf

  • isProperSubsetOf(potentialSuperset: Set<any>): boolean
  • Determines whether every element of this set is an element of the provided set and the provided set contains at least one element not in this set.

    Parameters

    • potentialSuperset: Set<any>

    Returns boolean

isProperSupersetOf

  • isProperSupersetOf(potentialSubset: Set<any>): boolean
  • Determines whether every element of the provided set is an element of this set and this set contains at least one element not in the provided set.

    Parameters

    • potentialSubset: Set<any>

    Returns boolean

isSubsetOf

  • isSubsetOf(potentialSuperset: Set<any>): boolean
  • Determines whether every element of this set is an element of the provided set.

    Parameters

    • potentialSuperset: Set<any>

    Returns boolean

isSupersetOf

  • isSupersetOf(potentialSubset: Set<any>): boolean
  • Determines whether every element of the provided set is an element of this set.

    Parameters

    • potentialSubset: Set<any>

    Returns boolean

union

  • union<U>(other: Set<U>): XSet<T | U>
  • Returns a set containing all the elements that are either in this or other.

    Type parameters

    • U

    Parameters

    • other: Set<U>

    Returns XSet<T | U>

xor

  • xor<U>(other: Set<U>): XSet<T | U>
  • Returns a set of all the elements that are either only in this or only in other. The returned set will not include elements that are in both sets.

    Other libaries call this operation symmetric difference or disjunctive union.

    Type parameters

    • U

    Parameters

    • other: Set<U>

    Returns XSet<T | U>

Generated using TypeDoc