intersectionBy
intersection, comparing by a computed key instead of value equality.
Lecture
Same shape as differenceBy,
opposite condition: intersectionBy(f, iterable1, iterable2)
walks iterable2 and keeps each element
whose f-key is found among iterable1's
f-keys, deduplicated by that key. f applies to
both iterables, so both must share the same element type A
— only the comparison key type B can differ from
A.
This is the natural match for two lists of full records that share an
identifying field: a list of "featured" SKUs and a product catalog, a
list of active-user IDs and a list of full user objects, and so on.
intersection itself is
intersectionBy((a) => a, iterable1, iterable2).
No chain method exists; call the data-first function or its async
counterpart. The concurrency marker from .concurrent(n)
applies to iterable2, exactly as with
intersectionAsync.
Demo 1 · Basics
Demo 2 · Async, with concurrency
Try it yourself
Exercise: use intersectionBy (keyed on 'sku')
to find products that are on sale.
intersection — the value-equality version ·
differenceBy — exclude by a shared computed key instead ·
uniqBy — dedupe a single iterable by key ·
compress — filter by a parallel boolean mask