Options
All
  • Public
  • Public/Protected
  • All
Menu

Creates a Collection.Keyed

Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

Type parameters

  • K

  • V

  • K

  • V

Callable

  • Keyed<K, V>(collection: Iterable<[K, V]>): Keyed<K, V>
  • Keyed<V>(obj: object): Keyed<string, V>
  • Keyed<K, V>(collection: Iterable<[K, V]>): Keyed<K, V>
  • Keyed<V>(obj: object): Keyed<string, V>
  • Keyed<K, V>(): Keyed<K, V>
  • Keyed(): Keyed<any, any>
  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Type parameters

    • K

    • V

    Parameters

    Returns Keyed<K, V>

  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Type parameters

    • V

    Parameters

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

    Returns Keyed<string, V>

  • Always returns a Seq.Keyed, if input is not keyed, expects an collection of [K, V] tuples.

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

    Type parameters

    • K

    • V

    Parameters

    Returns Keyed<K, V>

  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Type parameters

    • V

    Parameters

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

    Returns Keyed<string, V>

  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Type parameters

    • K

    • V

    Returns Keyed<K, V>

  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Returns Keyed<any, any>

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

Keyed

  • Keyed<K, V>(collection: Iterable<[K, V]>): Keyed<K, V>
  • Keyed<V>(obj: object): Keyed<string, V>
  • Creates a Collection.Keyed

    Similar to Collection(), however it expects collection-likes of [K, V] tuples if not constructed from a Collection.Keyed or JS Object.

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

    Type parameters

    • K

    • V

    Parameters

    Returns Keyed<K, V>

  • Type parameters

    • V

    Parameters

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

    Returns Keyed<string, V>

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>

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

Methods

__@iterator

concat

  • concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Keyed<K | KC, V | VC>
  • concat<C>(...collections: Array<object>): Keyed<K | string, V | C>
  • concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Keyed<K | KC, V | VC>
  • concat<C>(...collections: Array<object>): Keyed<K | string, V | C>
  • Returns a new Collection with other collections concatenated to this one.

    Type parameters

    • KC

    • VC

    Parameters

    • Rest ...collections: Array<Iterable<[KC, VC]>>

    Returns Keyed<K | KC, V | VC>

  • Type parameters

    • C

    Parameters

    • Rest ...collections: Array<object>

    Returns Keyed<K | string, V | C>

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

    All entries will be present in the resulting Seq, even if they have the same key.

    Type parameters

    • KC

    • VC

    Parameters

    • Rest ...collections: Array<Iterable<[KC, VC]>>

    Returns Keyed<K | KC, V | VC>

  • Type parameters

    • C

    Parameters

    • Rest ...collections: Array<object>

    Returns Keyed<K | string, V | C>

filter

  • filter<F>(predicate: function, context?: any): Keyed<K, F>
  • filter(predicate: function, context?: any): this
  • filter<F>(predicate: function, context?: any): Keyed<K, 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: V

    Parameters

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

          • value: V
          • key: K
          • iter: this

          Returns boolean

    • Optional context: any

    Returns Keyed<K, F>

  • Parameters

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

          • value: V
          • key: K
          • iter: this

          Returns any

    • Optional context: any

    Returns this

  • Returns a new Seq with only the entries 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: V

    Parameters

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

          • value: V
          • key: K
          • iter: this

          Returns boolean

    • Optional context: any

    Returns Keyed<K, F>

  • Parameters

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

          • value: V
          • key: K
          • iter: this

          Returns any

    • Optional context: any

    Returns this

flatMap

  • flatMap<KM, VM>(mapper: function, context?: any): Keyed<KM, VM>
  • flatMap<KM, VM>(mapper: function, context?: any): Keyed<KM, VM>
  • Flat-maps the Collection, returning a Collection of the same type.

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

    Type parameters

    • KM

    • VM

    Parameters

    • mapper: function
        • (value: V, key: K, iter: this): Iterable<[KM, VM]>
        • Parameters

          • value: V
          • key: K
          • iter: this

          Returns Iterable<[KM, VM]>

    • Optional context: any

    Returns Keyed<KM, VM>

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

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

    Type parameters

    • KM

    • VM

    Parameters

    • mapper: function
        • (value: V, key: K, iter: this): Iterable<[KM, VM]>
        • Parameters

          • value: V
          • key: K
          • iter: this

          Returns Iterable<[KM, VM]>

    • Optional context: any

    Returns Keyed<KM, VM>

flip

  • Returns a new Collection.Keyed of the same type where the keys and values have been flipped.

    const { Map } = require('immutable')
    Map({ a: 'z', b: 'y' }).flip()
    // Map { "z": "a", "y": "b" }

    Returns Keyed<V, K>

  • see

    Collection.Keyed.flip

    Returns Keyed<V, K>

map

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

    const { Collection } = require('immutable')
    Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
    // Seq { "a": 10, "b": 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: V, key: K, iter: this): M
        • Parameters

          • value: V
          • key: K
          • iter: this

          Returns M

    • Optional context: any

    Returns Keyed<K, M>

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

    const { Seq } = require('immutable')
    Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
    // Seq { "a": 10, "b": 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: V, key: K, iter: this): M
        • Parameters

          • value: V
          • key: K
          • iter: this

          Returns M

    • Optional context: any

    Returns Keyed<K, M>

mapEntries

  • mapEntries<KM, VM>(mapper: function, context?: any): Keyed<KM, VM>
  • mapEntries<KM, VM>(mapper: function, context?: any): Keyed<KM, VM>
  • Returns a new Collection.Keyed of the same type with entries ([key, value] tuples) passed through a mapper function.

    const { Map } = require('immutable')
    Map({ a: 1, b: 2 })
      .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
    // Map { "A": 2, "B": 4 }

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

    Type parameters

    • KM

    • VM

    Parameters

    • mapper: function
        • (entry: [K, V], index: number, iter: this): [KM, VM]
        • Parameters

          • entry: [K, V]
          • index: number
          • iter: this

          Returns [KM, VM]

    • Optional context: any

    Returns Keyed<KM, VM>

  • see

    Collection.Keyed.mapEntries

    Type parameters

    • KM

    • VM

    Parameters

    • mapper: function
        • (entry: [K, V], index: number, iter: this): [KM, VM]
        • Parameters

          • entry: [K, V]
          • index: number
          • iter: this

          Returns [KM, VM]

    • Optional context: any

    Returns Keyed<KM, VM>

mapKeys

  • mapKeys<M>(mapper: function, context?: any): Keyed<M, V>
  • mapKeys<M>(mapper: function, context?: any): Keyed<M, V>
  • Returns a new Collection.Keyed of the same type with keys passed through a mapper function.

    const { Map } = require('immutable')
    Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
    // Map { "A": 1, "B": 2 }

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

    Type parameters

    • M

    Parameters

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

          • key: K
          • value: V
          • iter: this

          Returns M

    • Optional context: any

    Returns Keyed<M, V>

  • see

    Collection.Keyed.mapKeys

    Type parameters

    • M

    Parameters

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

          • key: K
          • value: V
          • iter: this

          Returns M

    • Optional context: any

    Returns Keyed<M, V>

toArray

  • toArray(): Array<[K, V]>
  • toArray(): Array<[K, V]>
  • Shallowly converts this collection to an Array.

    Returns Array<[K, V]>

  • Shallowly converts this collection to an Array.

    Returns Array<[K, V]>

toJS

  • Deeply converts this Keyed collection to equivalent native JavaScript Object.

    Converts keys to Strings.

    Returns Object

  • Deeply converts this Keyed Seq to equivalent native JavaScript Object.

    Converts keys to Strings.

    Returns Object

toJSON

  • toJSON(): object
  • toJSON(): object
  • Shallowly converts this Keyed collection to equivalent native JavaScript Object.

    Converts keys to Strings.

    Returns object

    • [key: string]: V
  • Shallowly converts this Keyed Seq to equivalent native JavaScript Object.

    Converts keys to Strings.

    Returns object

    • [key: string]: V

toSeq

  • toSeq(): Keyed<K, V>
  • toSeq(): this
  • Returns Seq.Keyed.

    override

    Returns Keyed<K, V>

  • Returns itself

    Returns this

Generated using TypeDoc