@pengzhanbo/utils - v3.4.1
    Preparing search index...

    Function compose

    • compose multiple functions, right to left

      组合多个函数,从右到左执行

      Type Parameters

      • T extends ComposeFn[] = ComposeFn[]

      Parameters

      • ...fns: T

        The functions to compose. 要组合的函数

      Returns (...args: Parameters<LastArray<T>>) => ReturnType<FirstArray<T>>

      A new function that is the composition of the input functions. 由输入函数组合而成的新函数

      const add = (a) => a + 1
      const subtract = (a) => a - 2
      const multiply = (a, b) => a * b
      compose(add, subtract, multiply)(1, 2) // => (1 * 2) - 2 + 1 = 1