Function apply

  • Creates a new vector by applying a function component-wise to the components of one or more input vectors.

    Type Parameters

    • N extends number[]

    Parameters

    • fn: (...n: N) => number

      The function to apply to each component.

    • ...v: { [Property in string | number | symbol]: Vector }

      The vectors.

    Returns Vector

    The resulting vector.

    apply((a, b) => a + b, [1, 2, 3], [4, 5, 6]); // [5, 7, 9]
    
    apply((i) => i * 2, [1, 2, 3]); // [2, 4, 6]
    
    apply((a, b) => a + (b - a) / 2, [1, 2, 3], [4, 5, 6]); // [2.5, 3.5, 4.5]