Future Javascript: new data structures(Records & Tuples )

Future Javascript: new data structures(Records & Tuples )

Records & Tuples are new immutable data structures to JavaScript .currently this proposal is on stage 2 and Alot of library implement similar concepts, such asImmutable.js.

We define a record or tuple expression by using the # in front of otherwise normal object or array expressions

Record: a deeply immutable Object data structure #{ x: 1, y: 2 }
Tuple: a deeply immutable Array data structure #[1, 2, 3, 4]

Records and Tuples are easily introspectable in a debugger, while library provided immutable types are often hard to inspect as you have to inspect through data structure details.

Records and Tuples can only contain primitives and other Records and Tuples. You could think of Records and Tuples as "compound primitives". By being thoroughly based on primitives, not objects, Records and Tuples are deeply immutable.

Additionally, this proposal introduces a third new primitive type(Box)to ergonomically store object references inside Records and Tuples: #{ prop: Box(object) }.

Records and Tuples support comfortable idioms for construction, manipulation and use, similar to working with objects and Arrays. They are compared deeply by their contents, rather than by their identity.

Examples:

Record

1.png

Tuple

2.png

Box

3.png

if you wanna more details you cann find them here : l[github.com/tc39/proposal-record-tuple]

enjoy !!