differenceBy
difference, comparing by a computed key instead of value equality.
Lecture
fxDifferenceBy(f, iterable1, iterable2) follows the exact
same argument-order rule as difference:
the result comes from iterable2, keeping
only the elements whose f-key does not appear
among iterable1's f-keys (with duplicates in
the result collapsed). The f function is applied to
both iterables, so — unlike differenceBy in some
languages — both arguments must share the same element type
A; only the derived key values (of type B) are
what's being compared.
This is the shape you reach for when the "exclusion list" and the
"source list" are full records rather than bare values: a list of
blocked user objects and a list of user objects, matched by
id; or an unavailable-products list and a product catalog,
matched by sku.
difference itself is just
fxDifferenceBy((a) => a, iterable1, iterable2). Both also
exist as chain methods (.differenceBy(f, other)), where the
receiver is iterable2 and other is
iterable1. On the
async side, the concurrency marker applies to iterable2,
same as fxDifferenceAsync.
Demo 1 · Basics
Demo 2 · Async, with concurrency
Try it yourself
Exercise: use differenceBy (keyed on 'sku')
to find products that are still available.
difference — the value-equality version ·
intersectionBy — keep by a shared computed key instead ·
uniqBy — dedupe a single iterable by key ·
fxCompress — filter by a parallel boolean mask