ecmascript-immutable-data-structures

  • 所有者: sebmarkbage/ecmascript-immutable-data-structures
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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 ===.

Record

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

Immutable Vector

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

Immutable Map

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

Immutable Set

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

Status of this Proposal

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.

Known Issues

See why this matters.

主要指标

概览
名称与所有者sebmarkbage/ecmascript-immutable-data-structures
主编程语言
编程语言 (语言数: 0)
平台
许可证
所有者活动
创建于2014-09-24 21:54:14
推送于2017-03-09 08:49:37
最后一次提交2017-03-08 21:51:46
发布数0
用户参与
星数603
关注者数61
派生数16
提交数16
已启用问题?
问题数15
打开的问题数13
拉请求数2
打开的拉请求数1
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?