<B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (
self: Iterable<A>
) => Iterable<C>
<A, B, C>(
self: Iterable<A>,
that: Iterable<B>,
f: (a: A, b: B) => C
): Iterable<C>Applies a function to pairs of elements at the same index in two Iterables, collecting the results. If one
input Iterable is short, excess elements of the longer Iterable are discarded.
Example (Zipping with a combining function)
import { Iterable } from "effect"
// Add corresponding elements
const a = [1, 2, 3, 4]
const b = [10, 20, 30, 40]
const sums = Iterable.zipWith(a, b, (x, y) => x + y)
console.log(Array.from(sums)) // [11, 22, 33, 44]
// Combine strings
const firstNames = ["John", "Jane", "Bob"]
const lastNames = ["Doe", "Smith", "Johnson"]
const fullNames = Iterable.zipWith(
firstNames,
lastNames,
(first, last) => `${first} ${last}`
)
console.log(Array.from(fullNames)) // ["John Doe", "Jane Smith", "Bob Johnson"]
// Different lengths - stops at shorter
const short = [1, 2]
const long = ["a", "b", "c", "d"]
const combined = Iterable.zipWith(
short,
long,
(num, letter) => `${num}${letter}`
)
console.log(Array.from(combined)) // ["1a", "2b"]
// Complex transformations
const prices = [10.99, 25.50, 5.00]
const quantities = [2, 1, 3]
const totals = Iterable.zipWith(prices, quantities, (price, qty) => {
return Math.round(price * qty * 100) / 100 // round to 2 decimal places
})
console.log(Array.from(totals)) // [21.98, 25.5, 15]export const const zipWith: {
<B, A, C>(
that: Iterable<B>,
f: (a: A, b: B) => C
): (self: Iterable<A>) => Iterable<C>
<A, B, C>(
self: Iterable<A>,
that: Iterable<B>,
f: (a: A, b: B) => C
): Iterable<C>
}
Applies a function to pairs of elements at the same index in two Iterables, collecting the results. If one
input Iterable is short, excess elements of the longer Iterable are discarded.
Example (Zipping with a combining function)
import { Iterable } from "effect"
// Add corresponding elements
const a = [1, 2, 3, 4]
const b = [10, 20, 30, 40]
const sums = Iterable.zipWith(a, b, (x, y) => x + y)
console.log(Array.from(sums)) // [11, 22, 33, 44]
// Combine strings
const firstNames = ["John", "Jane", "Bob"]
const lastNames = ["Doe", "Smith", "Johnson"]
const fullNames = Iterable.zipWith(
firstNames,
lastNames,
(first, last) => `${first} ${last}`
)
console.log(Array.from(fullNames)) // ["John Doe", "Jane Smith", "Bob Johnson"]
// Different lengths - stops at shorter
const short = [1, 2]
const long = ["a", "b", "c", "d"]
const combined = Iterable.zipWith(
short,
long,
(num, letter) => `${num}${letter}`
)
console.log(Array.from(combined)) // ["1a", "2b"]
// Complex transformations
const prices = [10.99, 25.50, 5.00]
const quantities = [2, 1, 3]
const totals = Iterable.zipWith(prices, quantities, (price, qty) => {
return Math.round(price * qty * 100) / 100 // round to 2 decimal places
})
console.log(Array.from(totals)) // [21.98, 25.5, 15]
zipWith: {
<function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>B, function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>A, function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>C>(that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>A, b: Bb: function (type parameter) B in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>B) => function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>C): (self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) C in <B, A, C>(that: Iterable<B>, f: (a: A, b: B) => C): (self: Iterable<A>) => Iterable<C>C>
<function (type parameter) A in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A, function (type parameter) B in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B, function (type parameter) C in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A, b: Bb: function (type parameter) B in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B) => function (type parameter) C in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) C in <A, B, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C>
} = import dualdual(3, <function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B, function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A, function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B>, f: (a: A, b: B) => Cf: (a: Aa: function (type parameter) A in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>A, b: Bb: function (type parameter) B in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>B) => function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) C in <B, A, C>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => C): Iterable<C>C> => ({
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]() {
const const selfIterator: Iterator<A, any, any>selfIterator = self: Iterable<A>self[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
const const thatIterator: Iterator<B, any, any>thatIterator = that: Iterable<B>that[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
return {
Iterator<C, any, any>.next(...[value]: [] | [any]): IteratorResult<C, any>next() {
const const selfResult: IteratorResult<A, any>selfResult = const selfIterator: Iterator<A, any, any>selfIterator.Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next()
const const thatResult: IteratorResult<B, any>thatResult = const thatIterator: Iterator<B, any, any>thatIterator.Iterator<B, any, any>.next(...[value]: [] | [any]): IteratorResult<B, any>next()
if (const selfResult: IteratorResult<A, any>selfResult.done?: boolean | undefineddone || const thatResult: IteratorResult<B, any>thatResult.done?: boolean | undefineddone) {
return { IteratorReturnResult<TReturn>.done: truedone: true, IteratorReturnResult<any>.value: anyvalue: var undefinedundefined }
}
return { IteratorYieldResult<TYield>.done?: false | undefineddone: false, IteratorYieldResult<C>.value: Cvalue: f: (a: A, b: B) => Cf(const selfResult: IteratorYieldResult<A>selfResult.IteratorYieldResult<A>.value: Avalue, const thatResult: IteratorYieldResult<B>thatResult.IteratorYieldResult<B>.value: Bvalue) }
}
}
}
}))