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:
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:
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 newSeq
.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 JavaScriptArray
.For example, the following performs no work, because the resulting Seq's values are never iterated:
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:
Seq allows for the efficient chaining of operations, allowing for the expression of logic that can otherwise be very tedious:
As well as expressing logic that would otherwise be memory or time limited:
Seq is often used to provide a rich collection API to JavaScript Object.