-
Notifications
You must be signed in to change notification settings - Fork 4
CS2 Discussion: Features: Literal-notation for Map-Types #43
Comments
Could this be combined with YAML support #59? Does YAML have a concept of a map? |
The trouble is that there are two notions of key-value "maps" in ES6, objects and @mitar YAML has notation for key-value maps, but it's exactly what CS uses for objects, namely
YAML does offer explicit typing via
I've never found this particularly pretty notation, but it's an option... To me, a natural syntax for
This would get translated to
(or perhaps something more efficient) By contrast,
is getting translated to
which stringifies |
It would be pretty interesting to 'adopt' YAML's tagging syntax for structures and sequences, then a !Map
stringKey: value1
? object # using canonical mapping syntax
: value2 |
Closing due to lack of interest. |
Migrated to jashkenas/coffeescript#4939 |
I truly welcome the arrival of
Set
- andMap
-types. The more i use esp. maps i'd like to use a literal for map-types. One can initialize aMap
using a nested-arraybut thats really ugly. In an ideal world it could be written like a object-literal
m = new Map ( 1: 'one', [2]: 'two' )
or simplyas this might seem to be ambiguous, maybe with a type-hint
Such a type-hint might serve as a solution to the for-loop-problem on iterables as well. If no hint was given, CS would assume a object in case of
for-of
-loop. If a hint was given then translate into afor (var [k, v] of myMap)
-style-loop for a map-type orfor (let elem of mySet)
I'd love to see member-access via bracket-notation naturally like so
I was surprised to learn that Gorillascript has already introduced a literal-notation for 'first-class-members' set- and map-types. It uses the ampersand to distinguish objects from maps
In an ideal world one could do destructuring-assignments on map-types, the same way it can be done with objects.
Since the profiling-results on map- and set-types that float around on the web are not convincing, no literal-notation is avail, no bracket-notation and no destructuring at the moment there is not much reason to prefer maps instead of objects, unless one wants to use objects as keys of the map. A literal-notation for map-types might change this a bit.
This is not a proposal for types in CS thru the backdoor - but maybe we could stick to the for-loops as they are by using such a tiny annotation ?
The text was updated successfully, but these errors were encountered: