HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.12k stars 650 forks source link

[enhancement] REST / SPREAD operator #5741

Closed zabojad closed 7 years ago

zabojad commented 7 years ago

ES6 has a REST and SPREAD operator usable on arrays.

The latest ES6 proposal has even REAST/SPREAD on objects. This is already usable and largely used with transpilers like Babel.

This ... operator is very useful especially with libraries like Redux and React that require the developer to implement pure functions very often (it eases the duplication of objects/arrays for example)...

I would love to use it with my favourite language... Would that be something hard to add to the Haxe syntax?

nadako commented 7 years ago

I don't particularly like that ... syntax, but speaking of object copying, I'd love to see some syntax support for persistent data structures similar to OCaml's { myObj with field1=value1; field2=value2 }.

zabojad commented 7 years ago

@nadako have you been using the spread operator on real projects? It is very handy...

The OCaml syntax you propose is very verbose when duplicating fields from objects having many fields... I do not say it's bad but it would be suitable for different use cases... Maybe both would be welcome in the haxe syntax though :)...

dstrekelj commented 7 years ago

Both rest and spread are nice to work with, from my (limited) experience. I think they'd fit in nicely with the functional aspect of Haxe. But who knows how much work it would take for the implementations to be consistent and efficient on all supported languages.

The macro context is, of course, pretty powerful and can realise some of the other ES2015 features such as destructuring. However, the problem then is that it only works in the macro context.

I'd love to see Haxe's syntax evolve as ECMAScript's various proposals mature and become standardised, but it's easier said than done.

fullofcaffeine commented 7 years ago

Just as a reminder, syntax changes should be proposed through the evolution process: http://haxe.org/blog/haxe-evolution-process.

But yes, I do agree, would be nice to see the operator... since we're into it, can we get short lambdas too? Seriously!

zabojad commented 7 years ago

Guys, I just did not hear about this haxe evolution process until now. Thank you for pointing it to me!

I think this ticket can be closed and handled right in the evolution tracker... I'll reference the new ticket here.

zabojad commented 7 years ago

https://github.com/HaxeFoundation/haxe-evolution/pull/7