Git Product home page Git Product logo

ecmascript-immutable-data-structures's Introduction

Immutable Records, Vectors, Maps and Sets for ECMAScript

Immutability and referential transparency has many known benefits and ability for optimization. Several modern JavaScript libraries take advantage of this, and many more functional compile-to-JS languages.

This is based upon the Value Types proposal (Typed Objects / Explainer).

All these types provide value equality for both == and ===.

Records are a new value type that represents the value type analogy of an immutable object.

const xy = #{ x: 1, y: 2 }; // frozen value type
const xyz = #{ ...xy, z: 3 }; // functional extension

ImmutableVector is a new value type that represents the value type analogy of an immutable array, without holes. It cannot be sparse.

const xy = #[ x, y ]; // frozen value type
const xyz = #[ ...xy, z ]; // functional extension

ImmutableMap is an immutable version of Map. Any mutable operation returns a new ImmutableMap instead of mutating the existing reference.

const a = ImmutableMap([['x', 1], ['y', 2]]);
const b = a.set('y', 3);
a.get('y'); // 2
b.get('y'); // 3

ImmutableSet is an immutable version of Set. Any mutable operation returns a new ImmutableSet instead of mutating the existing reference.

const a = ImmutableSet([1, 2]);
const b = a.add(3);
a.size; // 2
b.size; // 3

This was presented to TC39 in 2015 but the value of having it in the engine is still unproven and this is a large implementation burden for VMs. It effectively doubles the existing data structures. Therefore, we need to gather more arguments for why it needs to be included in the language and how it would be used.

See why this matters.

ecmascript-immutable-data-structures's People

Contributors

ckknight avatar nmn avatar sebmarkbage avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.