@nathanfaucett/immutable-list
v0.0.5
Published
immutable persistent linked list for the browser and node.js
Downloads
35
Maintainers
Readme
Immutable List
Immutable persistent linked list for the browser and node.js, ImmutableList can not be changed once created. Persistent data presents a mutative API which does not update the data in-place, but instead always yields new updated data.
This implementation is based on clojure's List.
Install using npm
$ npm install @nathanfaucett/immutable-list --saveInstall using yarn
$ yarn add @nathanfaucett/immutable-list --saveExample Usage
var ImmutableList = require("@nathanfaucett/immutable-list");
var a = new ImmutableList([0, 1, 2]),
b = new ImmutableList(0, 1, 2),
c = ImmutableList.of([0, 1, 2]),
d = ImmutableList.of(0, 1, 2);
var a0 = a.push(3), // returns a new list with 3 at the end of the list
a1 = a.unshift(-1); // returns a new list with -1 at the start of the listDocs
Members
length -> Number
returns size of List, only available if Object.defineProperty is supportedStatic Functions
List.isList(value: Any) -> Boolean
returns true if value is a list else falseList.of(...values: Array) -> List
creates List from passed values same as new List(...values: Array<Any>)List.equal(a: List, b: List) -> Boolean
compares lists by valuesFunctions
size() -> Number
returns size of Listget(index: UnsignedNumber) -> Any
returns value at indexnth(index: UnsignedNumber) -> Any
alias to getfirst() -> Any
returns first elementlast() -> Any
returns last elementindexOf(value: Any) -> Number
returns index of value, -1 if not foundset(index: UnsignedNumber, value: Any) -> List
returns new List if value at index is differentinsert(index: UnsignedNumber, ...values: Array) -> List
returns new List with inserted values at indexremove(index: UnsignedNumber[, count = 1: UnsignedNumber]) -> List
returns new List without the values from index to index + countconj(...values: Array) -> List
returns new List with values pushed to front of the Listunshift(...values: Array) -> List
alias to conjpop() -> List
returns new List without last elementshift() -> List
returns new List without first elementpush(...values: Array) -> List
returns new List with values pushed to end of the Listconcat(...lists: Array) -> List
returns new List with values from lists pushed to end of the Listiterator([reverse = false: Boolean]) -> Iterator
returns IteratortoArray() -> Array
returns List elements in an Arrayjoin([separator = " "]) -> String
join all elements of an List into a StringtoString() -> String
String representation of Listequals(other: List) -> Boolean
compares this list to other list by valuesevery, filter, forEach, forEachRight, map, reduce, reduceRight, some
common Array methods