Simple Interactive JS Console
List are singly linked lists which support efficient O(1) addition and removal from the front using unshift(value) and shift(). Wikipedia Persistent Data Structure Linked Lists
var a = ImmutableList.of(0, 1, 2, 3); var b = a.push(4, 5, 6); a.toArray(); // -> [0, 1, 2, 3] b.toArray(); // -> [0, 1, 2, 3, 4, 5, 6]
Vectors are ordered indexed collections. Understanding Clojure's Persistent Vector
var a = ImmutableVector.of(0, 1, 2, 3); var b = a.push(4, 5, 6); a.toArray(); // -> [0, 1, 2, 3] b.toArray(); // -> [0, 1, 2, 3, 4, 5, 6]
HashMap is an unordered collection of (key, value) pairs. Understanding Clojure's Persistent HashMap
var a = ImmutableHashMap.of({a: 0, b: 1}); var b = a.set("c", 2); a.toObject(); // -> {a: 0, b: 1} b.toObject(); // -> {a: 0, b: 1, c: 2}
Sets are a collection of unique values. It is a wrapper class where Set<V> = HashMap<V, Void>.
var a = ImmutableSet.of(0, 1, 2, 3); var b = a.set(2, 3, 4); a.toArray(); // -> [0, 1, 2, 3] b.toArray(); // -> [0, 1, 2, 3, 4]
A Record is a wrapper class around a HashMap with rescrited fields.
var Person = ImmutableRecord({ name: null }, "Person"); var a = new Person({name: "Bob"}); var b = a.set("name", "Billy"); a.toObject(); // -> {name: "Bob"} b.toObject(); // -> {name: "Billy"}