Function once

  • Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation. The func is invoked with the arguments of the created function.


    Returns the new restricted function.


    let func = x => x
    let single = once(func)
    single(1) // 1
    single(2) // 1
    single(3) // 1
    // ...
    // `func` is invoked only once.

    Type Parameters

    • T


    • func: Function<T>

      The function to restrict

    Returns Function<T>

Generated using TypeDoc