Skip to content

Regarding pair matching functions for SetDiffer #66

@spavikevik

Description

@spavikevik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions