/js-immutable-playground

immutable persistent data structure playground for the browser

Primary LanguageJavaScriptMIT LicenseMIT

Immutable Playground

Immutable persistent data structures playground

Immutable List

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]

Immutable 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]

Immutable 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}

Immutable Set

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]

Immutable Record

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"}