Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a sequence of values, but may not be backed by a concrete data structure.

Seq is immutable — Once a Seq is created, it cannot be changed, appended to, rearranged or otherwise modified. Instead, any mutative method called on a Seq will return a new Seq.

Seq is lazy — Seq does as little work as necessary to respond to any method call. Values are often created during iteration, including implicit iteration when reducing or converting to a concrete data structure such as a List or JavaScript Array.

For example, the following performs no work, because the resulting Seq's values are never iterated:

var oddSquares = Immutable.Seq.of(1,2,3,4,5,6,7,8)
.filter(x => x % 2).map(x => x * x);

Once the Seq is used, it performs only the work necessary. In this example, no intermediate data structures are ever created, filter is only called three times, and map is only called once:

console.log(oddSquares.get(1)); // 9

Seq allows for the efficient chaining of operations, allowing for the expression of logic that can otherwise be very tedious:

Immutable.Seq({a:1, b:1, c:1})
.flip().map(key => key.toUpperCase()).flip().toObject();
// Map { A: 1, B: 1, C: 1 }

As well as expressing logic that would otherwise be memory or time limited:

Immutable.Range(1, Infinity)
.skip(1000)
.map(n => -n)
.filter(n => n % 2 === 0)
.take(2)
.reduce((r, n) => r * n, 1);
// 1006008

Seq is often used to provide a rich collection API to JavaScript Object.

Immutable.Seq({ x: 0, y: 1, z: 2 }).map(v => v * 2).toObject();
// { x: 0, y: 2, z: 4 }

Index

Functions

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

    Type parameters

    • T

    Returns <internal>.Indexed<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Indexed<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Indexed<T>

  • Type parameters

    • K

    • V

    Parameters

    Returns <internal>.Indexed<any>

  • Type parameters

    • T

    Parameters

    • array: T[]

    Returns <internal>.Indexed<T>

  • Type parameters

    • T

    Parameters

    • iterator: Iterator<T>

    Returns <internal>.Indexed<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Indexed<T>

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

    Type parameters

    • K

    • V

    Returns <internal>.Keyed<K, V>

  • Type parameters

    • K

    • V

    Parameters

    Returns <internal>.Keyed<K, V>

  • Type parameters

    • K

    • V

    Parameters

    Returns <internal>.Keyed<K, V>

  • Type parameters

    • K

    • V

    Parameters

    • array: any[]

    Returns <internal>.Keyed<K, V>

  • Type parameters

    • V

    Parameters

    • obj: {}
      • [key: string]: V

    Returns <internal>.Keyed<string, V>

  • Type parameters

    • K

    • V

    Parameters

    • iterator: Iterator<any>

    Returns <internal>.Keyed<K, V>

  • Type parameters

    • K

    • V

    Parameters

    Returns <internal>.Keyed<K, V>

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

    Type parameters

    • T

    Returns <internal>.Set<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Set<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Set<T>

  • Type parameters

    • K

    • V

    Parameters

    Returns <internal>.Set<any>

  • Type parameters

    • T

    Parameters

    • array: T[]

    Returns <internal>.Set<T>

  • Type parameters

    • T

    Parameters

    • iterator: Iterator<T>

    Returns <internal>.Set<T>

  • Type parameters

    • T

    Parameters

    Returns <internal>.Set<T>

  • isSeq(maybeSeq: any): boolean
  • True if maybeSeq is a Seq, it is not backed by a concrete structure such as Map, List, or Set.

    Parameters

    • maybeSeq: any

    Returns boolean

  • Returns a Seq of the values provided. Alias for Seq.Indexed.of().

    Type parameters

    • T

    Parameters

    • Rest ...values: T[]

    Returns <internal>.Indexed<T>

Generated using TypeDoc