Skip to content

fix[intersectionBy]: match each mapped value at most once in lazy fp pipes - #2146

Merged
raon0211 merged 6 commits into
toss:mainfrom
poketopa:fix/fp-intersectionby-lazy-duplicates
Oct 22, 2026
Merged

raon0211 merged 6 commits into
toss:mainfrom
poketopa:fix/fp-intersectionby-lazy-duplicates

Conversation

@poketopa

Copy link
Copy Markdown
Contributor

Summary

During lazy evaluation, fp/intersectionBy keeps multiple values with the same mapped key, unlike its eager path.

import { intersectionBy, pipe, take } from 'es-toolkit/fp';

pipe([2.1, 2.2], intersectionBy([2.3, 3.4], Math.floor), take(2));
// Before: [2.1, 2.2]
// After:  [2.1]

Changes

  • Create a separate set of unmatched keys for each lazy run and remove each key after its first match.
  • Add regression tests for duplicate matches and reuse of the same operator.
  • Update the bundle size snapshot and changelog.

…luated lazily

The lazy transform only checked whether a mapped value was in the second
array, so every value with the same key was kept. The eager path calls the
main intersectionBy, which keeps only the first one. Track unmatched keys in
a set created for each run, like uniqBy does, so a reused function does not
carry state over from a previous run.
@vercel

vercel Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Oct 22, 2026 1:09am UTC

Request Review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raon0211
raon0211 merged commit 678c655 into toss:main Oct 22, 2026
12 checks passed

This branch was successfully deployed

1 active deployment
Preview — 88040e6f Deployed Oct 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants