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:
foo.map(x => x * x); foo.map(function (x) { return x * x; });
API fromJS()
Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
is()Value equality check with semantics similar to Object.is
, but treats Immutable Iterable
s as values, equal if the second Iterable
includes equivalent values.
Lists are ordered indexed dense collections, much like a JavaScript Array.
MapImmutable 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().
SetA 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 add
ed.
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.
Record.Class SeqRepresents a sequence of values, but may not be backed by a concrete data structure.
Seq.KeyedSeq
which represents key-value pairs.
Seq
which represents an ordered indexed list of values.
Seq
which represents a set of values.
The Iterable
is a set of (key, value) entries which can be iterated, and is the base class for all collections in immutable
, allowing them to make use of all the Iterable methods (such as map
and filter
).
Keyed Iterables have discrete keys tied to each value.
Iterable.IndexedIndexed 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.KeyedCollection
which represents key-value pairs.
Collection
which represents ordered indexed values.
Collection
which represents values, unassociated with keys or indices.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4