Options
All
  • Public
  • Public/Protected
  • All
Menu

Set Collections only represent values. They have no associated keys or indices. Duplicate values are possible in the lazy Seq.Sets, however the concrete Set Collection does not allow duplicate values.

Collection methods on Collection.Set such as map and forEach will provide the value as both the first and second arguments to the provided function.

const { Collection } = require('immutable')
const seq = Collection.Set([ 'A', 'B', 'C' ])
// Seq { "A", "B", "C" }
seq.forEach((v, k) =>
 assert.equal(v, k)
)

Type parameters

  • T

  • T

Callable

  • 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>

  • Always returns a Seq.Set, discarding associated indices or keys.

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

    Returns Set<any>

  • Set Collections only represent values. They have no associated keys or indices. Duplicate values are possible in the lazy Seq.Sets, however the concrete Set Collection does not allow duplicate values.

    Collection methods on Collection.Set such as map and forEach will provide the value as both the first and second arguments to the provided function.

    const { Collection } = require('immutable')
    const seq = Collection.Set([ 'A', 'B', 'C' ])
    // Seq { "A", "B", "C" }
    seq.forEach((v, k) =>
     assert.equal(v, k)
    )

    Type parameters

    • T

    Returns Set<T>

  • Set Collections only represent values. They have no associated keys or indices. Duplicate values are possible in the lazy Seq.Sets, however the concrete Set Collection does not allow duplicate values.

    Collection methods on Collection.Set such as map and forEach will provide the value as both the first and second arguments to the provided function.

    const { Collection } = require('immutable')
    const seq = Collection.Set([ 'A', 'B', 'C' ])
    // Seq { "A", "B", "C" }
    seq.forEach((v, k) =>
     assert.equal(v, k)
    )

    Type parameters

    • T

    Parameters

    Returns Set<T>

Index

Variables

size

size: number | undefined

Some Seqs can describe their size lazily. When this is the case, size will be an integer. Otherwise it will be undefined.

For example, Seqs returned from map() or reverse() preserve the size of the original Seq while filter() does not.

Note: Range, Repeat and Seqs made from Arrays and Objects will always have a size.

Functions

Collection

  • Collection<I>(collection: I): I
  • 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

  • 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

Seq

  • Creates a Seq.

    Returns a particular kind of Seq based on the input.

    • If a Seq, that same Seq.
    • If an Collection, a Seq of the same kind (Keyed, Indexed, or Set).
    • If an Array-like, an Seq.Indexed.
    • If an Iterable Object, an Seq.Indexed.
    • If an Object, a Seq.Keyed.

    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: Seq is a conversion function and not a class, and does not use the new keyword during construction.

    Type parameters

    • S: Seq<any, any>

    Parameters

    • seq: S

    Returns S

  • Type parameters

    • K

    • V

    Parameters

    • collection: Keyed<K, V>

    Returns Keyed<K, V>

  • Type parameters

    • T

    Parameters

    Returns Indexed<T>

  • Type parameters

    • T

    Parameters

    • collection: Set<T>

    Returns Set<T>

  • Type parameters

    • T

    Parameters

    Returns Indexed<T>

  • Type parameters

    • V

    Parameters

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

    Returns Keyed<string, V>

  • Returns Seq<any, any>

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>

cacheResult

  • cacheResult(): this
  • Because Sequences are lazy and designed to be chained together, they do not cache their results. For example, this map function is called a total of 6 times, as each join iterates the Seq of three values.

    var squares = Seq([ 1, 2, 3 ]).map(x => x * x)
    squares.join() + squares.join()

    If you know a Seq will be used multiple times, it may be more efficient to first cache it in memory. Here, the map function is called only 3 times.

    var squares = Seq([ 1, 2, 3 ]).map(x => x * x).cacheResult()
    squares.join() + squares.join()

    Use this method judiciously, as it must fully evaluate a Seq which can be a burden on memory and possibly performance.

    Note: after calling cacheResult, a Seq will always have a size.

    Returns this

of

  • of<T>(...values: Array<T>): Set<T>
  • Returns a Seq.Set of the provided values

    Type parameters

    • T

    Parameters

    • Rest ...values: Array<T>

    Returns Set<T>

Methods

__@iterator

concat

  • concat<U>(...collections: Array<Iterable<U>>): Set<T | U>
  • concat<U>(...collections: Array<Iterable<U>>): Set<T | U>
  • Returns a new Collection with other collections concatenated to this one.

    Type parameters

    • U

    Parameters

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

    Returns Set<T | U>

  • Returns a new Seq with other collections concatenated to this one.

    All entries will be present in the resulting Seq, even if they are duplicates.

    Type parameters

    • U

    Parameters

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

    Returns Set<T | U>

filter

  • filter<F>(predicate: function, context?: any): Set<F>
  • filter(predicate: function, context?: any): this
  • filter<F>(predicate: function, context?: any): Set<F>
  • filter(predicate: function, context?: any): this
  • Returns a new Collection 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

  • Returns a new Seq 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>
  • flatMap<M>(mapper: function, context?: any): Set<M>
  • Flat-maps the Collection, returning a Collection of the same type.

    Similar to collection.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>

  • Flat-maps the Seq, returning a Seq of the same type.

    Similar to seq.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>

map

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

    Collection.Set([ 1, 2 ]).map(x => 10 * x)
    // Seq { 1, 2 }

    Note: map() always returns a new instance, even if it produced the same value at every step.

    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>

  • Returns a new Seq.Set with values passed through a mapper function.

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

    Note: map() always returns a new instance, even if it produced the same value at every step.

    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>

toArray

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

    Returns Array<T>

  • Shallowly converts this collection to an Array.

    Returns Array<T>

toJS

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

    Returns Array<any>

  • Deeply converts this Set Seq to equivalent native JavaScript Array.

    Returns Array<any>

toJSON

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

    Returns Array<T>

  • Shallowly converts this Set Seq to equivalent native JavaScript Array.

    Returns Array<T>

toSeq

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

    override

    Returns Set<T>

  • Returns itself

    Returns this

Generated using TypeDoc