Pipelines

It's common to want to call a series of functions, passing the result of one to the next. With the regular function call syntax this can be a little difficult to read as you have to read the code from the inside out.

Gleam's pipe operator |> helps with this problem by allowing you to write code top-to-bottom.

The pipe operator takes the result of the expression on its left and passes it as an argument to the function on its right.

If the right-hand expression is a function call then then the left-hand value will be used as the first argument to the call. For example, rocket |> launch(1, 2) would become launch(rocket, 1, 2).

If the right-hand expression is not a function call then then it will become one, and the left-hand value will be the sole argument to the call. For example, rocket |> launch would become launch(rocket).

Gleam code is typically written with the "subject" of the function as the first argument, to make it easier to pipe. If you wish to pipe to a different position then a function capture can be used to insert the argument to the desired position.

If you need to debug print a value in the middle of a pipeline you can use |> echo to do it.