Kipper
Kipper copied to clipboard
[Feature] Implement pipeline operator `|>`
Is there an existing proposal for this?
- [X] I have searched the existing issues
This feature does not exist in the latest version
- [X] I am using the latest version
Proposal
Implement new pipeline operator allowing for chained function call expressions that do not require nested expressions and can be chained like Linux pipes.
Syntax:
- Allows any form of expression to be evaluated and its value to be passed to another expression.
EXP |> EXP
- Ignores new-lines and allows formatted chaining, like this:
const result = val |> call func |> call func2 |> call func3;
Exact behaviour you want
Implement the |>
similarly to the implementation from Mozilla (MDN Docs - Pipeline operator |>
), which will pass the return of an expression to the next expression or function call in a chain.
Example for a simple function call pipeline:
val |> call func |> call func2 |> call func3 ...
Usage in expressions:
val + 5 |> _ ** 9 |> 50 + _ // -> Evaluates to a number
If possible, there should also be the option to pass other arguments to a pipeline function as well, where a new variable is used that stores the result of the previous pipe expression, like for example:
"arg" |> call func |> call func2(_, arg) // '_' should store the output of the previous pipe evaluation
This syntax should also allow code like this:
call func("arg") |> call func2(_, arg)