<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"]]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]>
} = dual<(...args: Array<any>) => any, <A, B>(self: Iterable<A>, that: Iterable<B>) => Iterable<[A, B]>>(arity: 2, body: <A, B>(self: Iterable<A>, that: Iterable<B>) => Iterable<[A, B]>): ((...args: Array<any>) => any) & (<A, B>(self: Iterable<A>, that: Iterable<B>) => Iterable<[A, B]>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
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)
)