scalaz/scalaz — pull request #707 by drstevens (2014-05-14 22:57:33+00:00)
Title: Fix behavior of List#groupWhen and groupWhenM. 

See https://groups.google.com/forum/#!topic/scalaz/OtEpQA20O8U

1. Change return type to `List.groupWhen` and `List.groupWhenM` to return `List[NonEmptyList[A]]` and `M[List[NonEmptyList[A]]` respectively.

2. Add tests to verify behavior below. These are somewhat pointless until better `Arbitrary[(A, B) => C]` can be implemented.

3. `List.groupWhen` and `List.groupWhenM` behaved strangely when predicate was something more complex than `_ == _`. Changed this to behave more reasonably.

Before:

scala> val l = (0 to 3) ++ (8 to 9) toList
l: List[Int] = List(0, 1, 2, 3, 8, 9)

scala> l groupWhen((x, y) => x-y < 2 && y-x < 2)
res0: List[List[Int]] = List(List(0, 1), List(2, 3), List(8, 9))

After

scala> l groupWhen((x, y) => x-y < 2 && y-x < 2)
res0: List[scalaz.NonEmptyList[Int]] = List(NonEmptyList(0, 1, 2, 3), NonEmptyList(8, 9))

scala> l.groupWhenM[Id]((x, y) => x-y < 2 && y-x < 2)
res1: scalaz.Scalaz.Id[List[scalaz.NonEmptyList[Int]]] = List(NonEmptyList(0, 1, 2, 3), NonEmptyList(8, 9))