intersection
difference's opposite: elements of the second iterable that ARE also found in the first.
Lecture
fxIntersection(iterable1, iterable2) shares
difference's argument-order convention: the result walks
iterable2, and keeps each element (in
iterable2's order, deduplicated) that is found in
iterable1. iterable1 is only ever used as a
membership set — swap the two arguments and you get the same
values in a set-theory sense, but the actual order (and which
collection's duplicates get collapsed) is different, since the source
of the yielded elements changes. See Demo 1.
Under the hood it's
fxIntersectionBy((a) => a, iterable1, iterable2) — reach
for intersectionBy
directly when you need to match by a computed key across two lists of
full records rather than by value equality.
The chain method is .intersection(other), and there the
receiver is iterable2 (the one that gets walked) while
other is iterable1 (the membership set). On the async
side, the concurrency marker from .concurrent(n) applies to
iterable2 — iterable1 is drained up front to
build the membership set.
Demo 1 · Basics & argument order
Demo 2 · Async, with concurrency
Try it yourself
Exercise: use intersection to find which of the
candidate's skills are actually required.
difference — the exclusion counterpart ·
intersectionBy — match by a computed key instead ·
uniq — dedupe a single iterable ·
fxIncludes — test membership of a single value