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

Sequential function apply operator #13

Open
Panzerschrek opened this issue Feb 16, 2024 · 1 comment
Open

Sequential function apply operator #13

Panzerschrek opened this issue Feb 16, 2024 · 1 comment

Comments

@Panzerschrek
Copy link
Owner

It would be nice to have some syntax to simplify code patterns like this:

auto x= 42;
auto y= Baz(Bar(Foo(x)));

My suggestion is to use some operator, like |> for this. Possible syntax:

auto y = x |> Foo |> Bar |> Baz; // Produces identical result to the previous example

Basically this is just some kind of syntax sugar.
I assume it should work for free function and class functions.

Also it may be helpful to support functions with more than one argument. Possible syntax:

auto a= b |> Foo c |> Bar d, e, f |> Baz;

() may be added for better readability, or they should be obligatory:

auto a= b |> Foo(c) |> Bar(d, e, f) |> Baz;

These two examples are equivalent to:

auto a= Baz(Bar(Foo(b, c), d, e, f));

Such piping operator is binary. It should be decided which priority should it have relative to other binary operators.

@Panzerschrek
Copy link
Owner Author

The whole idea seems to be a little bit controversial.
It adds no new value, only syntax sugar. It adds ambiguity which function exactly to call (some free function or a member). it adds ambiguity in combination with binary operators (which operator has bigger precedence).

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

1 participant