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

Using the tear off operator as a shorthand for (x) => x.foo #5

Open
xxgreg opened this issue May 24, 2015 · 1 comment
Open

Using the tear off operator as a shorthand for (x) => x.foo #5

xxgreg opened this issue May 24, 2015 · 1 comment

Comments

@xxgreg
Copy link

xxgreg commented May 24, 2015

I'd like there to be a short-hand for (x) => x.foo.

Assuming a symbol other than # is used for tear offs, i.e. perhaps :, thus removing the conflict with symbols, then (x) => x.foo could then be written as :foo.

This is useful with map. i.e. list.map((x) => x.foo) becomes list.map(:foo).

Another possibility is # could still be used and symbols could be made callable, so that #foo is also equivalent to (x) => x.foo when passed as a function.

Full example:

class Foo {
    Foo(this.bar);
    int bar;
}

List<Foo> foos = [new Foo(1), new Foo(2), new Foo(3)];

// :bar is identical to (x) => x.bar
List<int> bars = foos.map(:bar); // [1, 2, 3]
@seaneagan
Copy link

I filed a more general version of this here: dart-archive/dart_enhancement_proposals#17

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