Skip to content

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

@xxgreg

Description

@xxgreg

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions