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

Add "pluck" to quiver.mirrors #64

Closed
seaneagan opened this issue Nov 25, 2013 · 2 comments
Closed

Add "pluck" to quiver.mirrors #64

seaneagan opened this issue Nov 25, 2013 · 2 comments

Comments

@seaneagan
Copy link
Contributor

See http://underscorejs.org/#pluck

This doesn't fit in the core libraries, see http://dartbug.com/15278, since it requires mirrors.

Example implementation:

Iterable pluck(Iterable iterable, Symbol property) =>
    iterable.map((item) => reflect(item).getField(property).reflectee);

Usage:

main() {
  pluck([{'a': 1}, 'xx', [1, 2, 3]], #length).forEach(print);
}

Output:

1
2
3
@justinfagnani
Copy link
Contributor

I'm not sure I'd like to see this do into to Quiver. It basically save 6 characters, but throws out all static checking along the way. It makes sense in JavaScript because there's no short lambda syntax and no static checking anyway.

Without pluck you can extract a property with:

[{'a': 1}, 'xx', [1, 2, 3]].map((e) => e.length);

Which I also think is clearer.

@seaneagan
Copy link
Contributor Author

The main use case is when there is a dynamic property name, I was just too
lazy to come up with an example :). But I agree it may be too specialized
for quiver. Thanks for the feedback!

Cheers,
Sean Eagan

On Mon, Nov 25, 2013 at 11:21 AM, Justin Fagnani
notifications@github.comwrote:

I'm not sure I'd like to see this do into to Quiver. It basically save 6
characters, but throws out all static checking along the way. It makes
sense in JavaScript because there's no short lambda syntax and no static
checking anyway.

Without pluck you can extract a property with:

[{'a': 1}, 'xx', [1, 2, 3]].map((e) => e.length);

Which I also think is clearer.


Reply to this email directly or view it on GitHubhttps://github.com//issues/64#issuecomment-29221328
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants