-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
NonEmptyList.reduce used the wrong, or at least unexpected Semigroup instance for tuples of lists. I'm not sure if it's due to cats itself or the compiler though.
Let's say I want to semigroup combine a couple of tuples of lists
Tuple(List(1, 2)).combine(Tuple(List(5)))I would get Tuple(List(1, 2, 5)), which is expected.
However if I do
NonEmptyList.of(Tuple(List(1, 2)), Tuple(List(5))).reduceI would get Tuple(<function>). Looks like my tuples of lists not as tuples of List were inferred as tuples of (Int => Int) which is surprising. I would expect the same Semigroup instance would be used in both examples.
I even got
NonEmptyList.of((List(1, 2), List(1, 2), List(5, 6)), (List(4), List(5), List(7))).reduceto produce Tuple(List(1, 2, 4),List(1, 2, 5),<function1>) on my local machine using scala-cli on Scala 3.7.4 but I couldn't reproduce elsewhere.
Weirder still, this workaround that looks like it would do nothing
def reduce[T: Semigroup](xs: NonEmptyList[T]) =
xs.reduce
reduce(Tuple(List(1, 2)).combine(Tuple(List(5))))produces Tuple(List(1, 2, 5)).