<B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>
<A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>Computes the intersection of two arrays using Equal.equivalence(). Order is
determined by the first array.
When to use
Use when Effect equality is the right membership test and you want to keep values present in both inputs while preserving the first input's order.
Example (Computing array intersections)
import { Array } from "effect"
console.log(Array.intersection([1, 2, 3], [3, 4, 1])) // [1, 3]export const const intersection: {
<B>(that: Iterable<B>): <A>(
self: Iterable<A>
) => Array<A & B>
<A, B>(
self: Iterable<A>,
that: Iterable<B>
): Array<A & B>
}
Computes the intersection of two arrays using Equal.equivalence(). Order is
determined by the first array.
When to use
Use when Effect equality is the right membership test and you want to keep
values present in both inputs while preserving the first input's order.
Example (Computing array intersections)
import { Array } from "effect"
console.log(Array.intersection([1, 2, 3], [3, 4, 1])) // [1, 3]
intersection: {
<function (type parameter) B in <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<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>) => Array<A & B>B>): <function (type parameter) A in <A>(self: Iterable<A>): Array<A & B>A>(self: Iterable<A>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<A>): Array<A & B>A>) => interface Array<T>Array<function (type parameter) A in <A>(self: Iterable<A>): Array<A & B>A & function (type parameter) B in <B>(that: Iterable<B>): <A>(self: Iterable<A>) => Array<A & B>B>
<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>A, function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Array<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>): Array<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>): Array<A & B>B>): interface Array<T>Array<function (type parameter) A in <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>A & function (type parameter) B in <A, B>(self: Iterable<A>, that: Iterable<B>): Array<A & B>B>
} = const intersectionWith: <unknown>(
isEquivalent: (
self: unknown,
that: unknown
) => boolean
) => {
(that: Iterable<unknown>): (
self: Iterable<unknown>
) => unknown[]
(
self: Iterable<unknown>,
that: Iterable<unknown>
): unknown[]
}
Computes the intersection of two arrays using a custom equivalence. Order is
determined by the first array.
When to use
Use when you need to keep only values present in both arrays and equality
must be defined by a custom comparator, such as matching objects by id.
Example (Computing intersections with custom equality)
import { Array } from "effect"
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]
const array2 = [{ id: 3 }, { id: 4 }, { id: 1 }]
const isEquivalent = (a: { id: number }, b: { id: number }) => a.id === b.id
console.log(Array.intersectionWith(isEquivalent)(array2)(array1)) // [{ id: 1 }, { id: 3 }]
intersectionWith(import EqualEqual.const asEquivalence: <
A
>() => Equivalence<A>
Wraps
equals
as an Equivalence<A>.
When to use
Use when you want to pass Equal.equals to APIs that require an
Equivalence.
Details
- Returns a function
(a: A, b: A) => boolean that delegates to
equals
.
- Pure; allocates a thin wrapper on each call.
Example (Deduplicating with Equal semantics)
import { Array, Equal } from "effect"
const eq = Equal.asEquivalence<number>()
const result = Array.dedupeWith([1, 2, 2, 3, 1], eq)
console.log(result) // [1, 2, 3]
asEquivalence())