Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regarding pair matching functions for SetDiffer #66

Open
spavikevik opened this issue Dec 10, 2024 · 0 comments
Open

Regarding pair matching functions for SetDiffer #66

spavikevik opened this issue Dec 10, 2024 · 0 comments

Comments

@spavikevik
Copy link

spavikevik commented Dec 10, 2024

Hi, thanks for the nice library! I have a small issue about the default SetDiffer instance which invokes the following method

private[difflicious] def diffPairByFunc[A](
obtained: Seq[A],
expected: Seq[A],
func: A => Any,
itemDiffer: Differ[A],
): (Vector[DiffResult], Boolean) = {
val matchedIndexes = mutable.BitSet.empty
val results = mutable.ArrayBuffer.empty[DiffResult]
val expWithIdx = expected.zipWithIndex
var allIsOk = true
obtained.foreach { a =>
val aMatchVal = func(a)
val found = expWithIdx.find {
case (e, idx) =>
if (!matchedIndexes.contains(idx) && aMatchVal == func(e)) {
val res = itemDiffer.diff(a, e)
results += res
matchedIndexes += idx
allIsOk &= res.isOk
true
} else {
false
}
}

The func passed in the default instance is identity, which results in pairs of matching elements paired by equality.

However, this amounts to a useless Differ instance unless one specifies a custom pairing function. I understand the utility of being able to specify a custom pairing function for an unordered collection but I'd also expect a reasonable default one that is smart enough to match elements that are similar, something akin to the example here:
softwaremill/diffx#6 (comment)

Or alternatively, it would be better to drop the default instance.

@spavikevik spavikevik changed the title Regarding pair matching functions Regarding pair matching functions for SetDiffer Dec 10, 2024
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

No branches or pull requests

1 participant