<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Iterable<[A, B]>
<A, B>(self: Iterable<A>, that: Iterable<B>): Iterable<[A, B]>Zips this Iterable crosswise with the specified Iterable.
Example (Generating cartesian pairs)
import { Iterable } from "effect"
// All pairs of numbers and letters
const numbers = [1, 2, 3]
const letters = ["a", "b"]
const pairs = Iterable.cartesian(numbers, letters)
console.log(Array.from(pairs))
// [[1, "a"], [1, "b"], [2, "a"], [2, "b"], [3, "a"], [3, "b"]]
// Generate coordinate grid
const x = [0, 1, 2]
const y = [0, 1]
const grid = Iterable.cartesian(x, y)
console.log(Array.from(grid))
// [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]
// All combinations for testing
const browsers = ["chrome", "firefox"]
const devices = ["desktop", "mobile", "tablet"]
const testMatrix = Iterable.cartesian(browsers, devices)
console.log(Array.from(testMatrix))
// [
// ["chrome", "desktop"], ["chrome", "mobile"], ["chrome", "tablet"],
// ["firefox", "desktop"], ["firefox", "mobile"], ["firefox", "tablet"]
// ]
// Empty iterable results in empty cartesian product
const empty = Iterable.empty<number>()
const withEmpty = Iterable.cartesian([1, 2], empty)
console.log(Array.from(withEmpty)) // []elements
Source effect/Iterable.ts:24417 lines
export const const cartesian: {
<B>(that: Iterable<B>): <A>(
self: Iterable<A>
) => Iterable<[A, B]>
<A, B>(
self: Iterable<A>,
that: Iterable<B>
): Iterable<[A, B]>
}
Zips this Iterable crosswise with the specified Iterable.
Example (Generating cartesian pairs)
import { Iterable } from "effect"
// All pairs of numbers and letters
const numbers = [1, 2, 3]
const letters = ["a", "b"]
const pairs = Iterable.cartesian(numbers, letters)
console.log(Array.from(pairs))
// [[1, "a"], [1, "b"], [2, "a"], [2, "b"], [3, "a"], [3, "b"]]
// Generate coordinate grid
const x = [0, 1, 2]
const y = [0, 1]
const grid = Iterable.cartesian(x, y)
console.log(Array.from(grid))
// [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]
// All combinations for testing
const browsers = ["chrome", "firefox"]
const devices = ["desktop", "mobile", "tablet"]
const testMatrix = Iterable.cartesian(browsers, devices)
console.log(Array.from(testMatrix))
// [
// ["chrome", "desktop"], ["chrome", "mobile"], ["chrome", "tablet"],
// ["firefox", "desktop"], ["firefox", "mobile"], ["firefox", "tablet"]
// ]
// Empty iterable results in empty cartesian product
const empty = Iterable.empty<number>()
const withEmpty = Iterable.cartesian([1, 2], empty)
console.log(Array.from(withEmpty)) // []
cartesian: {
<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 cartesianWith: <A, B, [A, B]>(self: Iterable<A>, that: Iterable<B>, f: (a: A, b: B) => [A, B]) => Iterable<[A, B]> (+1 overload)cartesianWith(self: Iterable<A>self, that: Iterable<B>that, (a: Aa, b: Bb) => [a: Aa, b: Bb])
)