typed-objects-explainer
typed-objects-explainer copied to clipboard
Add Record, Tuple, Map, and Set
Sebastien Markbage suggested the addition of four kinds of value types:
- Record
- Tuple
- Map
- Set
These are all things that conceptually could be built on what was written up till now but it would be a pain and likely far less efficient.
Records and tuples are both structural variations on the existing nominal types. So you could create a record or tuple without having to declare the type ahead of time. Creating a record like {f, g} would be roughly equivalent to dynamically creating a struct type like new ValueType({f: Any, g: Any}). Maps and sets are persistent maps/sets, they have a get API. Each of these would have a global wrapper Record and Tuple and hence would get a global prototype.
for in order for records should be consistent no matter the order of creation. map and set should be in the order of insertion.
cc @sebmarkbage
I created a separate repo for this proposal where I will expand on helpful prototypes of these built-ins:
https://github.com/sebmarkbage/ecmascript-immutable-data-structures