xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

ES2021 & Pipeline operator (|>) / 管道运算符 |>

ES2021 & Pipeline operator (|>) / 管道运算符 |>

demo


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-08-01
 * @modified
 *
 * @description Pipeline operator (|>) / 管道运算符 |>
 * @difficulty Easy Medium Hard
 * @complexity O(n)
 * @augments
 * @example
 * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Pipeline_operator
 * @solutions
 *
 */

const log = console.log;

/*

expression |> function

// 实验性管道运算符|>(当前处于阶段1)将表达式的值通过管道传递给函数。

*/

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


refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Pipeline_operator



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-08-01 17:46  xgqfrms  阅读(1177)  评论(5编辑  收藏  举报