Not planned
Description
Proposal Details
Motivation
The pipeline operator (|>
) is a feature seen in languages like Elixir, which allows for more readable and maintainable code by chaining function calls. Introducing a similar operator in Go can simplify complex function chains and improve code readability.
Proposal
Introduce a pipeline operator (|>
) in Go that allows chaining function calls. The operator will pass the result of the expression on its left as the first argument to the function on its right.
Example
// Current Go code
result := multiplyByTwo(subtractThree(addOne(5)))
// Proposed syntax with pipeline operator
result := 5 |> addOne |> subtractThree |> multiplyByTwo
Activity
gabyhelp commentedon Jul 21, 2024
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
mainjzb commentedon Jul 21, 2024
If there is no error handling improvement, the scope of application is very limited.
I still hope that official can introduce some error handling improvement. The most likely scenario is an error handle macro.
seankhliao commentedon Jul 21, 2024
Duplicate of #33361