Options
All
  • Public
  • Public/Protected
  • All
Menu

Indexed Collections have incrementing numeric keys. They exhibit slightly different behavior than Collection.Keyed for some methods in order to better mirror the behavior of JavaScript's Array, and add methods which do not make sense on non-indexed Collections such as indexOf.

Unlike JavaScript arrays, Collection.Indexeds are always dense. "Unset" indices and undefined indices are indistinguishable, and all indices from 0 to size are visited when iterated.

All Collection.Indexed methods return re-indexed Collections. In other words, indices always start at 0 and increment until size. If you wish to preserve indices, using them as keys, convert to a Collection.Keyed by calling toKeyedSeq.

Type parameters

  • T

  • T

Callable

  • Creates a new Collection.Indexed.

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

    Type parameters

    • T

    Parameters

    Returns Indexed<T>

  • Always returns Seq.Indexed, discarding associated keys and supplying incrementing indices.

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

    Returns Indexed<any>

  • Indexed Collections have incrementing numeric keys. They exhibit slightly different behavior than Collection.Keyed for some methods in order to better mirror the behavior of JavaScript's Array, and add methods which do not make sense on non-indexed Collections such as indexOf.

    Unlike JavaScript arrays, Collection.Indexeds are always dense. "Unset" indices and undefined indices are indistinguishable, and all indices from 0 to size are visited when iterated.

    All Collection.Indexed methods return re-indexed Collections. In other words, indices always start at 0 and increment until size. If you wish to preserve indices, using them as keys, convert to a Collection.Keyed by calling toKeyedSeq.

    Type parameters

    • T

    Returns Indexed<T>

  • Indexed Collections have incrementing numeric keys. They exhibit slightly different behavior than Collection.Keyed for some methods in order to better mirror the behavior of JavaScript's Array, and add methods which do not make sense on non-indexed Collections such as indexOf.

    Unlike JavaScript arrays, Collection.Indexeds are always dense. "Unset" indices and undefined indices are indistinguishable, and all indices from 0 to size are visited when iterated.

    All Collection.Indexed methods return re-indexed Collections. In other words, indices always start at 0 and increment until size. If you wish to preserve indices, using them as keys, convert to a Collection.Keyed by calling toKeyedSeq.

    Type parameters

    • T

    Parameters

    Returns Indexed<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

Indexed

  • Creates a new Collection.Indexed.

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

    Type parameters

    • T

    Parameters

    Returns Indexed<T>

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

of

  • of<T>(...values: Array<T>): Indexed<T>
  • Provides an Seq.Indexed of the values provided.

    Type parameters

    • T

    Parameters

    • Rest ...values: Array<T>

    Returns Indexed<T>

Methods

__@iterator

concat

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

    Type parameters

    • C

    Parameters

    • Rest ...valuesOrCollections: Array<Iterable<C> | C>

    Returns Indexed<T | C>

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

    Type parameters

    • C

    Parameters

    • Rest ...valuesOrCollections: Array<Iterable<C> | C>

    Returns Indexed<T | C>

filter

  • filter<F>(predicate: function, context?: any): Indexed<F>
  • filter(predicate: function, context?: any): this
  • filter<F>(predicate: function, context?: any): Indexed<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, index: number, iter: this): boolean
        • Parameters

          • value: T
          • index: number
          • iter: this

          Returns boolean

    • Optional context: any

    Returns Indexed<F>

  • Parameters

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

          • value: T
          • index: number
          • 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, index: number, iter: this): boolean
        • Parameters

          • value: T
          • index: number
          • iter: this

          Returns boolean

    • Optional context: any

    Returns Indexed<F>

  • Parameters

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

          • value: T
          • index: number
          • iter: this

          Returns any

    • Optional context: any

    Returns this

findIndex

  • findIndex(predicate: function, context?: any): number
  • Returns the first index in the Collection where a value satisfies the provided predicate function. Otherwise -1 is returned.

    Parameters

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

          • value: T
          • index: number
          • iter: this

          Returns boolean

    • Optional context: any

    Returns number

findLastIndex

  • findLastIndex(predicate: function, context?: any): number
  • Returns the last index in the Collection where a value satisfies the provided predicate function. Otherwise -1 is returned.

    Parameters

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

          • value: T
          • index: number
          • iter: this

          Returns boolean

    • Optional context: any

    Returns number

flatMap

  • flatMap<M>(mapper: function, context?: any): Indexed<M>
  • flatMap<M>(mapper: function, context?: any): Indexed<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: number, iter: this): Iterable<M>
        • Parameters

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

          Returns Iterable<M>

    • Optional context: any

    Returns Indexed<M>

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

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

    Type parameters

    • M

    Parameters

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

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

          Returns Iterable<M>

    • Optional context: any

    Returns Indexed<M>

fromEntrySeq

  • fromEntrySeq(): Keyed<any, any>
  • If this is a collection of [key, value] entry tuples, it will return a Seq.Keyed of those entries.

    Returns Keyed<any, any>

get

  • get<NSV>(index: number, notSetValue: NSV): T | NSV
  • get(index: number): T | undefined
  • Returns the value associated with the provided index, or notSetValue if the index is beyond the bounds of the Collection.

    index may be a negative number, which indexes back from the end of the Collection. s.get(-1) gets the last item in the Collection.

    Type parameters

    • NSV

    Parameters

    • index: number
    • notSetValue: NSV

    Returns T | NSV

  • Parameters

    • index: number

    Returns T | undefined

indexOf

  • indexOf(searchValue: T): number
  • Returns the first index at which a given value can be found in the Collection, or -1 if it is not present.

    Parameters

    • searchValue: T

    Returns number

interleave

  • interleave(...collections: Array<Collection<any, T>>): this
  • Returns a Collection of the same type with the provided collections interleaved into this collection.

    The resulting Collection includes the first item from each, then the second from each, etc.

    const { List } = require('immutable')
    List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
    // List [ 1, "A", 2, "B", 3, "C"" ]

    The shortest Collection stops interleave.

    List([ 1, 2, 3 ]).interleave(
      List([ 'A', 'B' ]),
      List([ 'X', 'Y', 'Z' ])
    )
    // List [ 1, "A", "X", 2, "B", "Y"" ]

    Since interleave() re-indexes values, it produces a complete copy, which has O(N) complexity.

    Note: interleave cannot be used in withMutations.

    Parameters

    Returns this

interpose

  • interpose(separator: T): this
  • Returns a Collection of the same type with separator between each item in this Collection.

    Parameters

    • separator: T

    Returns this

lastIndexOf

  • lastIndexOf(searchValue: T): number
  • Returns the last index at which a given value can be found in the Collection, or -1 if it is not present.

    Parameters

    • searchValue: T

    Returns number

map

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

    const { Collection } = require('immutable')
    Collection.Indexed([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: number, iter: this): M
        • Parameters

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

          Returns M

    • Optional context: any

    Returns Indexed<M>

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

    const { Seq } = require('immutable')
    Seq.Indexed([ 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: number, iter: this): M
        • Parameters

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

          Returns M

    • Optional context: any

    Returns Indexed<M>

splice

  • splice(index: number, removeNum: number, ...values: Array<T>): this
  • Splice returns a new indexed Collection by replacing a region of this Collection with new values. If values are not provided, it only skips the region to be removed.

    index may be a negative number, which indexes back from the end of the Collection. s.splice(-2) splices after the second to last item.

    const { List } = require('immutable')
    List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
    // List [ "a", "q", "r", "s", "d" ]

    Since splice() re-indexes values, it produces a complete copy, which has O(N) complexity.

    Note: splice cannot be used in withMutations.

    Parameters

    • index: number
    • removeNum: number
    • Rest ...values: Array<T>

    Returns this

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 Indexed collection to equivalent native JavaScript Array.

    Returns Array<any>

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

    Returns Array<any>

toJSON

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

    Returns Array<T>

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

    Returns Array<T>

toSeq

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

    override

    Returns Indexed<T>

  • Returns itself

    Returns this

zip

  • Returns a Collection of the same type "zipped" with the provided collections.

    Like zipWith, but using the default zipper: creating an Array.

    const a = List([ 1, 2, 3 ]);
    const b = List([ 4, 5, 6 ]);
    const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]

    Type parameters

    • U

    Parameters

    Returns Indexed<[T, U]>

  • Type parameters

    • U

    • V

    Parameters

    Returns Indexed<[T, U, V]>

  • Parameters

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<any>

  • Returns a Seq "zipped" with the provided collections.

    Like zipWith, but using the default zipper: creating an Array.

    const a = Seq([ 1, 2, 3 ]);
    const b = Seq([ 4, 5, 6 ]);
    const c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]

    Type parameters

    • U

    Parameters

    Returns Indexed<[T, U]>

  • Type parameters

    • U

    • V

    Parameters

    Returns Indexed<[T, U, V]>

  • Parameters

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<any>

zipAll

  • Returns a Collection "zipped" with the provided collections.

    Unlike zip, zipAll continues zipping until the longest collection is exhausted. Missing values from shorter collections are filled with undefined.

    const a = List([ 1, 2 ]);
    const b = List([ 3, 4, 5 ]);
    const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]

    Type parameters

    • U

    Parameters

    Returns Indexed<[T, U]>

  • Type parameters

    • U

    • V

    Parameters

    Returns Indexed<[T, U, V]>

  • Parameters

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<any>

  • Returns a Seq "zipped" with the provided collections.

    Unlike zip, zipAll continues zipping until the longest collection is exhausted. Missing values from shorter collections are filled with undefined.

    const a = Seq([ 1, 2 ]);
    const b = Seq([ 3, 4, 5 ]);
    const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]

    Type parameters

    • U

    Parameters

    Returns Indexed<[T, U]>

  • Type parameters

    • U

    • V

    Parameters

    Returns Indexed<[T, U, V]>

  • Parameters

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<any>

zipWith

  • Returns a Collection of the same type "zipped" with the provided collections by using a custom zipper function.

    const a = List([ 1, 2, 3 ]);
    const b = List([ 4, 5, 6 ]);
    const c = a.zipWith((a, b) => a + b, b);
    // List [ 5, 7, 9 ]

    Type parameters

    • U

    • Z

    Parameters

    • zipper: function
        • (value: T, otherValue: U): Z
        • Parameters

          • value: T
          • otherValue: U

          Returns Z

    • otherCollection: Collection<any, U>

    Returns Indexed<Z>

  • Type parameters

    • U

    • V

    • Z

    Parameters

    • zipper: function
        • (value: T, otherValue: U, thirdValue: V): Z
        • Parameters

          • value: T
          • otherValue: U
          • thirdValue: V

          Returns Z

    • otherCollection: Collection<any, U>
    • thirdCollection: Collection<any, V>

    Returns Indexed<Z>

  • Type parameters

    • Z

    Parameters

    • zipper: function
        • (...any: Array<any>): Z
        • Parameters

          • Rest ...any: Array<any>

          Returns Z

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<Z>

  • Returns a Seq "zipped" with the provided collections by using a custom zipper function.

    const a = Seq([ 1, 2, 3 ]);
    const b = Seq([ 4, 5, 6 ]);
    const c = a.zipWith((a, b) => a + b, b);
    // Seq [ 5, 7, 9 ]

    Type parameters

    • U

    • Z

    Parameters

    • zipper: function
        • (value: T, otherValue: U): Z
        • Parameters

          • value: T
          • otherValue: U

          Returns Z

    • otherCollection: Collection<any, U>

    Returns Indexed<Z>

  • Type parameters

    • U

    • V

    • Z

    Parameters

    • zipper: function
        • (value: T, otherValue: U, thirdValue: V): Z
        • Parameters

          • value: T
          • otherValue: U
          • thirdValue: V

          Returns Z

    • otherCollection: Collection<any, U>
    • thirdCollection: Collection<any, V>

    Returns Indexed<Z>

  • Type parameters

    • Z

    Parameters

    • zipper: function
        • (...any: Array<any>): Z
        • Parameters

          • Rest ...any: Array<any>

          Returns Z

    • Rest ...collections: Array<Collection<any, any>>

    Returns Indexed<Z>

Generated using TypeDoc