Skip to content

Home > robinson > pipe

pipe() function

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

从左向右执行函数。

Signature:

typescript
declare function pipe(...fns: Array<Function>): Function;
declare function pipe(...fns: Array<Function>): Function;

Parameters

ParameterTypeDescription
fnsArray<Function>要组合的函数。

Returns:

Function

{Function} - 返回一个组合后的函数。

Example

JavaScript
const addOne = x => x + 1;
const double = x => x * 2;
const piped = pipe(addOne, double);
piped(2);// 返回 6
const addOne = x => x + 1;
const double = x => x * 2;
const piped = pipe(addOne, double);
piped(2);// 返回 6

Released under the MIT License.