Immutable data encourages pure functions (data-in, data-out) and lends itself to much simpler application development and enabling techniques from functional programming such as lazy evaluation.
While designed to bring these powerful functional concepts to JavaScript, it presents an Object-Oriented API familiar to Javascript engineers and closely mirroring that of Array, Map, and Set. It is easy and efficient to convert to and from plain Javascript types.
Note: all examples are presented in ES6. To run in all browsers, they need to be translated to ES3. For example:
// ES6
foo.map(x => x * x);
// ES3
foo.map(function (x) { return x * x; });Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
Lists are ordered indexed dense collections, much like a JavaScript Array.
Immutable Map is an unordered Iterable.Keyed of (key, value) pairs with
O(log32 N) gets and O(log32 N) persistent sets.
A type of Map that has the additional guarantee that the iteration order of entries will be the order in which they were set().
A Collection of unique values with O(log32 N) adds and has.
A type of Set that has the additional guarantee that the iteration order of
values will be the order in which they were added.
Stacks are indexed collections which support very efficient O(1) addition
and removal from the front using unshift(v) and shift().
Returns a Seq.Indexed of numbers from start (inclusive) to end
(exclusive), by step, where start defaults to 0, step to 1, and end to
infinity. When start is equal to end, returns empty range.
Returns a Seq.Indexed of value repeated times times. When times is
not defined, returns an infinite Seq of value.
Creates a new Class which produces Record instances. A record is similar to a JS object, but enforce a specific set of allowed string keys, and have default values.
Represents a sequence of values, but may not be backed by a concrete data structure.
Seq which represents key-value pairs.
Seq which represents an ordered indexed list of values.
Seq which represents a set of values.
Keyed Iterables have discrete keys tied to each value.
Indexed Iterables have incrementing numeric keys. They exhibit
slightly different behavior than Iterable.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 Iterables such as indexOf.
Set Iterables only represent values. They have no associated keys or
indices. Duplicate values are possible in Seq.Sets, however the
concrete Set does not allow duplicate values.
Collection is the abstract base class for concrete data structures. It cannot be constructed directly.
Collection which represents key-value pairs.
Collection which represents ordered indexed values.
Collection which represents values, unassociated with keys or indices.