Prelude API
    Preparing search index...

    Function extend

    • Creates a generator that extends each value from an iterable with additional properties.

      Type Parameters

      • T

        Type of elements in the input iterable

      • U

        Type of the extension object to merge with each element

      Parameters

      • f: (value: T, index: number) => U

        Function that generates extension properties for each element

      Returns (values: Iterable<T>) => Generator<T & U, void, unknown>

      A function that takes an iterable and returns a generator of extended objects

      Objects that combine the original value with additional properties

      // Add an 'index' property to each element
      const withIndex = [...extend((_, i) => ({ index: i }))(['a', 'b', 'c'])]
      // Result: [{ '0': 'a', index: 0 }, { '0': 'b', index: 1 }, { '0': 'c', index: 2 }]
      // Extend objects with calculated properties
      const items = [{ value: 5 }, { value: 10 }, { value: 15 }]
      const withDouble = [...extend(item => ({ double: item.value * 2 }))(items)]
      // Result: [{ value: 5, double: 10 }, { value: 10, double: 20 }, { value: 15, double: 30 }]