Skip to content

fix(uniqWith): match lodash comparator argument order in compat#1729

Merged
raon0211 merged 1 commit into
toss:mainfrom
ATOM00blue:fix/uniqwith-comparator-order
May 22, 2026
Merged

fix(uniqWith): match lodash comparator argument order in compat#1729
raon0211 merged 1 commit into
toss:mainfrom
ATOM00blue:fix/uniqwith-comparator-order

Conversation

@ATOM00blue
Copy link
Copy Markdown
Contributor

Summary

es-toolkit/compat's uniqWith invoked the comparator with reversed argument order compared to lodash. lodash calls the comparator as (candidate, kept) (documented (arrVal, othVal)), but compat passed the comparator straight to the non-compat implementation, which calls it as (kept, candidate). Any asymmetric comparator silently produced different results after migrating from lodash.

Changes

  • Wrap the comparator in compat uniqWith so the toolkit's (kept, candidate) call is forwarded as comparator(candidate, kept), matching lodash.
  • Add a test asserting the comparator is invoked with (candidate, kept) order, plus a behavioral test for an asymmetric (subset) comparator.

The non-compat uniqWith keeps its own documented (item1, item2) semantics and is unchanged.

Test plan

  • yarn vitest run src/compat/array/uniqWith.spec.ts — 19 passed (new tests fail before the fix)
  • yarn vitest run src/compat/array/ — 1000 passed
  • non-compat uniqWith unaffected; typecheck + lint clean

Closes #1728

The compat `uniqWith` passed the comparator straight to the non-compat
implementation, which invokes it as `(kept, candidate)`. lodash documents
and invokes the comparator as `(candidate, kept)`, so asymmetric
comparators produced different results after migrating to es-toolkit/compat.

Wrap the comparator to swap the arguments so the call order matches lodash.
Copilot AI review requested due to automatic review settings May 21, 2026 02:59
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

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

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment May 21, 2026 3:04am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes es-toolkit/compat’s uniqWith to match lodash’s documented comparator argument order, ensuring asymmetric comparators behave identically when migrating from lodash.

Changes:

  • Update compat uniqWith to swap comparator arguments so calls become (candidate, kept) (lodash-compatible).
  • Add tests to assert comparator invocation order and verify behavior with an asymmetric “subset” comparator.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/compat/array/uniqWith.ts Wraps the comparator to forward toolkit’s (kept, candidate) invocation as lodash’s (candidate, kept).
src/compat/array/uniqWith.spec.ts Adds tests covering comparator argument order and an asymmetric comparator behavioral case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching ths!

@raon0211 raon0211 merged commit 03ca6ea into toss:main May 22, 2026
11 of 12 checks passed
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.

uniqWith (compat) calls comparator with reversed argument order vs lodash

3 participants