<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>
<A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>Takes two Iterables and returns an Iterable of corresponding pairs.
Example (Zipping iterables)
import { Iterable } from "effect"
const numbers = [1, 2, 3]
const letters = ["a", "b", "c"]
const zipped = Iterable.zip(numbers, letters)
console.log(Array.from(zipped)) // [[1, "a"], [2, "b"], [3, "c"]]
// Different lengths - shorter one determines result length
const short = [1, 2]
const long = ["a", "b", "c", "d"]
const partial = Iterable.zip(short, long)
console.log(Array.from(partial)) // [[1, "a"], [2, "b"]]
// Works with any iterables
const range = Iterable.range(1, 3)
const word = "abc"
const mixed = Iterable.zip(range, word)
console.log(Array.from(mixed)) // [[1, "a"], [2, "b"], [3, "c"]]
// Create indexed pairs
const values = ["apple", "banana", "cherry"]
const indices = Iterable.range(0, 2)
const indexed = Iterable.zip(indices, values)
console.log(Array.from(indexed)) // [[0, "apple"], [1, "banana"], [2, "cherry"]]zipping
Source effect/Iterable.ts:8797 lines
export const const zip: {
<B>(that: Iterable<B>): <A>(
self: Iterable<A>
) => Iterable<[A, B]>
<A, B>(
self: Iterable<A>,
that: Iterable<B>
): Iterable<[A, B]>
}
Takes two Iterables and returns an Iterable of corresponding pairs.
Example (Zipping iterables)
import { Iterable } from "effect"
const numbers = [1, 2, 3]
const letters = ["a", "b", "c"]
const zipped = Iterable.zip(numbers, letters)
console.log(Array.from(zipped)) // [[1, "a"], [2, "b"], [3, "c"]]
// Different lengths - shorter one determines result length
const short = [1, 2]
const long = ["a", "b", "c", "d"]
const partial = Iterable.zip(short, long)
console.log(Array.from(partial)) // [[1, "a"], [2, "b"]]
// Works with any iterables
const range = Iterable.range(1, 3)
const word = "abc"
const mixed = Iterable.zip(range, word)
console.log(Array.from(mixed)) // [[1, "a"], [2, "b"], [3, "c"]]
// Create indexed pairs
const values = ["apple", "banana", "cherry"]
const indices = Iterable.range(0, 2)
const indexed = Iterable.zip(indices, values)
console.log(Array.from(indexed)) // [[0, "apple"], [1, "banana"], [2, "cherry"]]
zip: {
<function (type parameter) B in <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>B>(that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>B>): <function (type parameter) A in <A>(self: Iterable<A>): Iterable<[A, B]>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Iterable<[A, B]>A>) => interface Iterable<T, TReturn = any, TNext = any>Iterable<[function (type parameter) A in <A>(self: Iterable<A>): Iterable<[A, B]>A, function (type parameter) B in <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>B]>
<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A, function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B>): interface Iterable<T, TReturn = any, TNext = any>Iterable<[function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A, function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B]>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A, function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A>, that: Iterable<B>that: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B>): interface Iterable<T, TReturn = any, TNext = any>Iterable<[function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>A, function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>B]> => const zipWith: <A, B, [a: A, b: B]>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => [a: A, b: B]) => Iterable<[a: A, b: B]> (+1 overload)zipWith(self: Iterable<A>self, that: Iterable<B>that, import TupleTuple.const make: <
Elements extends ReadonlyArray<unknown>
>(
...elements: Elements
) => Elements
Creates a tuple from the provided arguments.
When to use
Use when you need a properly typed tuple without writing [a, b, c] as const
or another manual cast.
Details
The returned value has the exact tuple type, with each element's literal type
preserved.
Example (Creating a tuple)
import { Tuple } from "effect"
const point = Tuple.make(10, 20, "red")
console.log(point) // [10, 20, "red"]
make)
)