The experimental pipeline operator |>
(currently at stage 1) pipes the value of an expression into a function. This allows the creation of chained function calls in a readable manner. The result is syntactic sugar in which a function call with a single argument can be written like this:
let url = "%21" |> decodeURI;
The equivalent call in traditional syntax looks like this:
let url = decodeURI("%21");
expression |> function
The value of the specified expression
is passed into the function
as its sole parameter.
expression
function
The pipeline operator can improve readability when chaining several functions.
const double = (n) => n * 2; const increment = (n) => n + 1; // without pipeline operator double(increment(double(double(5)))); // 42 // with pipeline operator 5 |> double |> double |> increment |> double; // 42
Desktop | ||||||
---|---|---|---|---|---|---|
Pipeline operator (|> )
|
No | No | No | No | No | No |
Mobile | ||||||
---|---|---|---|---|---|---|
Pipeline operator (|> )
|
No | No | No | No | No | No |
Server | |
---|---|
Pipeline operator (|> )
|
No |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Pipeline_operator