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


Flag Counter

©xgqfrms 2012-2020

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



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM