-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add tuple or out parameters #421
Comments
This comment was originally written by [email protected] Removed Type-Defect label. |
There are some other possibilities for output parameters, using features already in the language. The closest to "out parameters" just uses closures, passing a setter of distance: The closure and variable closed over can be in a higher scope, and outside loops, if avoiding object creation is important: double distance; while (looping) { Or you can pass a handle to a double: Alternatively, pass in the calculation that needs multiple values as a callback: sphere.intersect(Ray ray, (Bool intersects, Double distance) { Map or list literals can be passed back. If you want to avoid object creation, you can use a static object, or pass one in. var result = intersect(ray); var out = new List(2) |
This comment was originally written by [email protected] Thanks for the comprehensive feedback. This bug can probably be closed. It would be interesting to see a blogpost/article on this as there are so many options and I imagine each has pros and cons. |
I'm closing this per the submitter's request. I will note that literal lists make it quite easy to return multiple values. Or passing in mutable list or map. I don't think we'll ever add out parameters. Added WontFix label. |
This comment was originally written by [email protected] I propose reopening this issue. I think all proposed methods have significant disadvantages:
I think there should be a way to pass the tuples of certain dimensions out of the function and ability to destructure them. For example: [User, bool] createOrUpdate(String name, id int) { User user, bool created = createOrUpdate("admin", 2); What do you think? |
This makes me (and I bet many others) very sad - tuples are one of the most useful sugar present in Python, Ruby, Go, etc.
in Dart I need specialized class for each case. There are at least two widely used patterns used as a workaround:
I bet there is way more code that would be much improved if this was allowed. |
Re-opening this for consideration. |
Fuchsia would very much like this feature. |
The new language repository is tracking this feature at dart-lang/language#68; presently 144 up-votes and a more recent and lively discussion; I proposed we close this in favor of that. |
I think this issue can be closed? |
This issue was originally filed by [email protected]
I have methods that I would like to return multiple values from. The two ways I could do this would be to return a tuple, or if output parameters were available I could use those.
I'd prefer output parameters to make it easier to optimize away copies of object references.
For example
or
The text was updated successfully, but these errors were encountered: