effect-io-ai

Package: effect
Module: Array

Array.intersectionWith

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 }]

See

Signature

declare const intersectionWith: <A>(isEquivalent: (self: A, that: A) => boolean) => { (that: Iterable<A>): (self: Iterable<A>) => Array<A>; (self: Iterable<A>, that: Iterable<A>): Array<A>; }

Source

Since v2.0.0