I am wondering why the following call of groupBy
does not work: My predicate is x < y
, so I expect [1, 6]
to be a group, but instead, Haskell put [1, 6, 4, 2]
into a group.
Prelude Data.List> groupBy (\x y -> x < y) [8,5,3,2,1,6,4,2]
[[8],[5],[3],[2],[1,6,4,2]]
More strangely, when I change the last number to -2, I expect the same behavior as in the above example. That is, since both 2 and -2 are less than 4, I expect that in the result [1, 6, 4, -2]
would make up a group. But instead, This time, Haskell put -2 to be a group.
Prelude Data.List> groupBy (\x y -> x < y) [8,5,3,2,1,6,4,-2]
[[8],[5],[3],[2],[1,6,4],[-2]]
Do I have a wrong understanding of groupBy
?