-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi, thanks for the nice library! I have a small issue about the default SetDiffer
instance which invokes the following method
difflicious/modules/core/src/main/scala/difflicious/differ/SeqDiffer.scala
Lines 151 to 174 in f4b0c74
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.