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

    Function tap

    • Tap into a value, execute a side-effect function, and return the original value. Useful for debugging or side-effects in pipe/compose chains.

      拦截一个值,执行副作用函数,然后返回原始值。 适用于 pipe/compose 链中的调试或副作用场景。

      Type Parameters

      • T

        The type of the value / 值的类型

      Parameters

      • value: T

        The value to tap into / 要拦截的值

      • fn: (value: T) => void

        The side-effect function / 副作用函数

      Returns T

      The original value, unchanged / 原始值,不变

      The return value of fn is ignored; only the side-effect matters. fn接收的返回值被忽略,只有副作用有意义。

      const result = tap('hello', console.log)
      // logs: 'hello'
      // result === 'hello'
    • Create a tap function that executes a side-effect and returns the value. Useful for inline use in pipe/compose chains.

      创建一个拦截函数,执行副作用后返回值。 适用于 pipe/compose 链中的内联使用。

      Type Parameters

      • T

        The type of the value / 值的类型

      Parameters

      • fn: (value: T) => void

        The side-effect function / 副作用函数

      Returns (value: T) => T

      A function that taps into a value / 一个拦截函数

      const debug = tap(console.log)
      pipe(parse, debug, validate)