Skip to content

intersect

TypeScript only
left.intersect(right)

Given two relations with the same heading, find tuples that appear in both.

Example: I want to find products that are both bestsellers AND on sale.

The set intersection of two relations. The result contains only those tuples that exist in both left and right.

The result’s heading is identical with that of the inputs’.

The headings of the two relations must be identical.

const myPurchases = Bmg([
{ product_id: 10, quantity: 2 },
{ product_id: 10, quantity: 4 },
{ product_id: 20, quantity: 1 },
])
const yourPurchases = Bmg([
{ product_id: 10, quantity: 2 },
{ product_id: 10, quantity: 4 },
{ product_id: 20, quantity: 5 },
{ product_id: 30, quantity: 1 },
])
myPurchases.intersect(yourPurchases).toArray()
// =>
// [{ product_id: 10, quantity: 2 },
// { product_id: 10, quantity: 4 }]
OperatorResult
unionTuples in either relation
intersectTuples in both relations
minusTuples in left but not right