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.
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.
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.
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.
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.
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.
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 Seq
s made from Array
s and Object
s will
always have a size.
Creates a Collection.
The type of Collection created is based on the input.
Collection
, that same Collection
.Collection.Indexed
.Collection.Indexed
.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.
Creates a Collection.
The type of Collection created is based on the input.
Collection
, that same Collection
.Collection.Indexed
.Collection.Indexed
.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.
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.
Creates a Seq.
Returns a particular kind of Seq
based on the input.
Seq
, that same Seq
.Collection
, a Seq
of the same kind (Keyed, Indexed, or Set).Seq.Indexed
.Seq.Indexed
.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.
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 a new Collection with other collections concatenated to this one.
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.
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.
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.
Flat-maps the Collection, returning a Collection of the same type.
Similar to collection.map(...).flatten(true)
.
Flat-maps the Seq, returning a Seq of the same type.
Similar to seq.map(...).flatten(true)
.
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.
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.
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.
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.
Shallowly converts this collection to an Array.
Shallowly converts this collection to an Array.
Shallowly converts this Keyed collection to equivalent native JavaScript Object.
Converts keys to Strings.
Shallowly converts this Keyed Seq to equivalent native JavaScript Object.
Converts keys to Strings.
Returns Seq.Keyed.
Returns itself
Generated using TypeDoc
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 thenew
keyword during construction.