Creates a generator that extends each value from an iterable with additional properties.
Type of elements in the input iterable
Type of the extension object to merge with each element
Function that generates extension properties for each element
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 elementconst withIndex = [...extend((_, i) => ({ index: i }))(['a', 'b', 'c'])]// Result: [{ '0': 'a', index: 0 }, { '0': 'b', index: 1 }, { '0': 'c', index: 2 }] Copy
// Add an 'index' property to each elementconst 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 propertiesconst 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 }] Copy
// Extend objects with calculated propertiesconst 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 }]
Creates a generator that extends each value from an iterable with additional properties.