Skip to content

proposal: Pipeline Operator for Go #68534

Not planned
Not planned
@KINGMJ

Description

@KINGMJ

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

gabyhelp commented on Jul 21, 2024

@gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

mainjzb

mainjzb commented on Jul 21, 2024

@mainjzb

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

seankhliao commented on Jul 21, 2024

@seankhliao
Member

Duplicate of #33361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @KINGMJ@seankhliao@mainjzb@gabyhelp

        Issue actions

          proposal: Pipeline Operator for Go · Issue #68534 · golang/go