Skip to content
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

Enhancement request: A List method to return a new List containing a certain property of each List member. #15278

Closed
DartBot opened this issue Nov 23, 2013 · 2 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 23, 2013

This issue was originally filed by @xximranxx


Say you have a class:

class Basic {
 int x;
 Basic(this.x);
}

and a list of this class:

main() {
 List<Basic> basic_list = [new Basic(1),new Basic(2)];
}

Now it would be nice to have a method to return a List of the x property of each List member:

main() {
 List<Basic> basic_list = [new Basic(1),new Basic(2)];
 List<int> int_list = basic_list.getPropertyList('x');
 for(int tmp_x in int_list) {
   print(tmp_x);
 }
}

would output:
1
2

Thanks,
Imran

@lrhn
Copy link
Member

lrhn commented Nov 25, 2013

To access an object property by name, you need to use mirrors.

We don't generally put that kind of functionality into the core libraries, so the feature as described is not going to happen.

We have a very similar functionality in the "map" method, but you have to pass a function that gets the x property, like "list.map((o)=>o.x)". It is lazy and returns an Iterable, so if you need a list, you can do:
  list.map((o) => o.x).toList()


Removed Area-Documentation, Type-Defect labels.
Added Area-Library, Type-Enhancement, NotPlanned labels.

@DartBot
Copy link
Author

DartBot commented Nov 25, 2013

This comment was originally written by @seaneagan


I added a feature request to quiver, to see if this fits there:

google/quiver-dart#64

@DartBot DartBot added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. Type-Enhancement closed-not-planned Closed as we don't intend to take action on the reported issue labels Nov 25, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants