-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add "Spread operator" #7023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Removed Type-Defect label. |
This comment was originally written by @kaendfinger This is very useful, I used to be a huge user of Groovy, so I know how it feels to use them. In future versions of the spec, this would a great addition! |
This comment was originally written by @seaneagan So: parents*.name would be equivalent to: parents.map((parent) => parent == null ? null : parent.name); I think more useful would be having a way of closurizing instance methods from a class instead of instance, then if issue #41 is fixed adding a "?" option to that, so something like: parents.map(Parent?.name) class Parent { |
Here's an updated link to the relevant Groovy feature: http://groovy-lang.org/operators.html#_spread_operator |
This is a pretty neat idea—Groovy has quite a few good ideas in it, but we don't feel it's a good fit for Dart. In general, my rule is to avoid operators or punctuation syntax unless you use it to refer to something that users have already learned. The problem is that if you use punctuation for something novel, users can't read it. If I've never used the Passing a lambda to |
Splat/spread is useful for more than just maps. For example: [
*someArray,
someIndividualThing,
someOtherIndividualThing
] ...would give an array containing each element of |
@nic-hartley that's discussed/planned currently. Check the dart-lang/language repo |
Right, we are planning to implement this now. See: https://github.com/dart-lang/language/blob/master/accepted/future-releases/spread-collections/feature-specification.md |
Oh, neat! I didn't see the other repo. Cool! |
This issue was originally filed by [email protected]
I did not find any informations about this operator during my Dart trip :
The spread operator allows to invoke an action on all items of an aggregate object. It is equivalent to calling the collect method like so:
(translated in Dart from Groovy exemple)
parent*.action; //equivalent to:
parent.forEach((child) { child?.action; });
or
List<Parent> parents;
[. . .]
List<String> parentNames = parents*.name
Groovy page discribing this operator:
http://groovy.codehaus.org/Operators
Thanks for your support,
Adrien
The text was updated successfully, but these errors were encountered: