Options
All
  • Public
  • Public/Protected
  • All
Menu

A Collection of unique values with O(log32 N) adds and has.

When iterating a Set, the entries will be (value, value) pairs. Iteration order of a Set is undefined, however is stable. Multiple iterations of the same Set will iterate in the same order.

Set values, like Map keys, may be of any type. Equality is determined using Immutable.is, enabling Sets to uniquely include other Immutable collections, custom value types, and NaN.

Type parameters

  • T

Callable

  • Create a new immutable Set containing the values of the provided collection-like.

    Note: Set is a factory function and not a class, and does not use the new keyword during construction.

    Returns Set<any>

  • A Collection of unique values with O(log32 N) adds and has.

    When iterating a Set, the entries will be (value, value) pairs. Iteration order of a Set is undefined, however is stable. Multiple iterations of the same Set will iterate in the same order.

    Set values, like Map keys, may be of any type. Equality is determined using Immutable.is, enabling Sets to uniquely include other Immutable collections, custom value types, and NaN.

    Type parameters

    • T

    Returns Set<T>

  • A Collection of unique values with O(log32 N) adds and has.

    When iterating a Set, the entries will be (value, value) pairs. Iteration order of a Set is undefined, however is stable. Multiple iterations of the same Set will iterate in the same order.

    Set values, like Map keys, may be of any type. Equality is determined using Immutable.is, enabling Sets to uniquely include other Immutable collections, custom value types, and NaN.

    Type parameters

    • T

    Parameters

    Returns Set<T>

Index

Properties

size

size: number

The number of items in this Set.

Functions

fromKeys

  • fromKeys<T>(iter: Collection<T, any>): Set<T>
  • fromKeys(obj: object): Set<string>
  • Set.fromKeys() creates a new immutable Set containing the keys from this Collection or JavaScript Object.

    Type parameters

    • T

    Parameters

    Returns Set<T>

  • Parameters

    • obj: object
      • [key: string]: any

    Returns Set<string>

isSet

  • isSet(maybeSet: any): boolean
  • True if the provided value is a Set

    Parameters

    • maybeSet: any

    Returns boolean

of

  • of<T>(...values: Array<T>): Set<T>
  • Creates a new Set containing values.

    Type parameters

    • T

    Parameters

    • Rest ...values: Array<T>

    Returns Set<T>

Methods

Collection

  • Collection<I>(collection: I): I
  • Creates a Collection.

    The type of Collection created is based on the input.

    • If an Collection, that same Collection.
    • If an Array-like, an Collection.Indexed.
    • If an Object with an Iterator defined, an Collection.Indexed.
    • If an Object, an Collection.Keyed.

    This methods forces the conversion of Objects and Strings to Collections. If you want to ensure that a Collection of one item is returned, use Seq.of.

    Note: An Iterator itself will be treated as an object, becoming a Seq.Keyed, which is usually not what you want. You should turn your Iterator Object into an iterable object by defining a Symbol.iterator (or @@iterator) method which returns this.

    Note: Collection is a conversion function and not a class, and does not use the new keyword during construction.

    Type parameters

    Parameters

    • collection: I

    Returns I

Set

  • Similar to Collection(), but always returns a Collection.Set.

    Note: Collection.Set is a factory function and not a class, and does not use the new keyword during construction.

    Type parameters

    • T

    Parameters

    Returns Set<T>

__@iterator

add

  • add(value: T): this
  • Returns a new Set which also includes this value.

    Note: add can be used in withMutations.

    Parameters

    • value: T

    Returns this

asImmutable

  • asImmutable(): this
  • see

    Map#asImmutable

    Returns this

asMutable

  • asMutable(): this
  • Note: Not all methods can be used on a mutable collection or within withMutations! Check the documentation for each method to see if it mentions being safe to use in withMutations.

    see

    Map#asMutable

    Returns this

clear

  • clear(): this
  • Returns a new Set containing no values.

    Note: clear can be used in withMutations.

    Returns this

concat

  • concat<C>(...collections: Array<Iterable<C>>): Set<T | C>
  • Type parameters

    • C

    Parameters

    • Rest ...collections: Array<Iterable<C>>

    Returns Set<T | C>

delete

  • delete(value: T): this
  • Returns a new Set which excludes this value.

    Note: delete can be used in withMutations.

    Note: delete cannot be safely used in IE8, use remove if supporting old browsers.

    alias

    remove

    Parameters

    • value: T

    Returns this

filter

  • filter<F>(predicate: function, context?: any): Set<F>
  • filter(predicate: function, context?: any): this
  • Returns a new Set with only the values for which the predicate function returns true.

    Note: filter() always returns a new instance, even if it results in not filtering out any values.

    Type parameters

    • F: T

    Parameters

    • predicate: function
        • (value: T, key: T, iter: this): boolean
        • Parameters

          • value: T
          • key: T
          • iter: this

          Returns boolean

    • Optional context: any

    Returns Set<F>

  • Parameters

    • predicate: function
        • (value: T, key: T, iter: this): any
        • Parameters

          • value: T
          • key: T
          • iter: this

          Returns any

    • Optional context: any

    Returns this

flatMap

  • flatMap<M>(mapper: function, context?: any): Set<M>
  • Flat-maps the Set, returning a new Set.

    Similar to set.map(...).flatten(true).

    Type parameters

    • M

    Parameters

    • mapper: function
        • (value: T, key: T, iter: this): Iterable<M>
        • Parameters

          • value: T
          • key: T
          • iter: this

          Returns Iterable<M>

    • Optional context: any

    Returns Set<M>

intersect

  • Returns a Set which has removed any values not also contained within collections.

    Note: intersect can be used in withMutations.

    Parameters

    • Rest ...collections: Array<Iterable<T>>

    Returns this

  • Set.intersect() creates a new immutable Set that is the intersection of a collection of other sets.

    const { Set } = require('immutable')
    const intersected = Set.intersect([
      Set([ 'a', 'b', 'c' ])
      Set([ 'c', 'a', 't' ])
    ])
    // Set [ "a", "c"" ]

    Type parameters

    • T

    Parameters

    Returns Set<T>

map

  • map<M>(mapper: function, context?: any): Set<M>
  • Returns a new Set with values passed through a mapper function.

    Set([1,2]).map(x => 10 * x)
    // Set [10,20]

    Type parameters

    • M

    Parameters

    • mapper: function
        • (value: T, key: T, iter: this): M
        • Parameters

          • value: T
          • key: T
          • iter: this

          Returns M

    • Optional context: any

    Returns Set<M>

merge

  • merge<C>(...collections: Array<Iterable<C>>): Set<T | C>
  • Type parameters

    • C

    Parameters

    • Rest ...collections: Array<Iterable<C>>

    Returns Set<T | C>

remove

  • remove(value: T): this
  • Parameters

    • value: T

    Returns this

subtract

  • subtract(...collections: Array<Iterable<T>>): this
  • Returns a Set excluding any values contained within collections.

    const { OrderedSet } = require('immutable')
    OrderedSet([ 1, 2, 3 ]).subtract([1, 3])
    // OrderedSet [2]

    Note: subtract can be used in withMutations.

    Parameters

    • Rest ...collections: Array<Iterable<T>>

    Returns this

toArray

  • toArray(): Array<T>
  • Shallowly converts this collection to an Array.

    Returns Array<T>

toJS

  • toJS(): Array<any>
  • Deeply converts this Set collection to equivalent native JavaScript Array.

    Returns Array<any>

toJSON

  • toJSON(): Array<T>
  • Shallowly converts this Set collection to equivalent native JavaScript Array.

    Returns Array<T>

toSeq

  • toSeq(): Set<T>
  • Returns Seq.Set.

    override

    Returns Set<T>

union

  • Returns a Set including any value from collections that does not already exist in this Set.

    Note: union can be used in withMutations.

    alias

    merge

    alias

    concat

    Type parameters

    • C

    Parameters

    • Rest ...collections: Array<Iterable<C>>

    Returns Set<T | C>

  • Set.union() creates a new immutable Set that is the union of a collection of other sets.

    const { Set } = require('immutable')
    const unioned = Set.union([
      Set([ 'a', 'b', 'c' ])
      Set([ 'c', 'a', 't' ])
    ])
    // Set [ "a", "b", "c", "t"" ]

    Type parameters

    • T

    Parameters

    Returns Set<T>

wasAltered

  • wasAltered(): boolean
  • see

    Map#wasAltered

    Returns boolean

withMutations

  • withMutations(mutator: function): this
  • Note: Not all methods can be used on a mutable collection or within withMutations! Check the documentation for each method to see if it mentions being safe to use in withMutations.

    see

    Map#withMutations

    Parameters

    • mutator: function
        • (mutable: this): any
        • Parameters

          • mutable: this

          Returns any

    Returns this

Generated using TypeDoc