We continue the separation of ascending subequences...
@Jerzy : I like your plan to use combinators.
Then let's remove (visible) recursion completely:
map (map fst ) $ groupBy (const snd)
$ zip xs ( True : zipWith (<=) xs (tail xs))
Hmmm, I didn't find it... Perhaps at that time I didn't acquire yet a sufficient level of perversion...
Well, the truth is that I had problems with groupBy! People discovered that the "standard" groupBy, which was sometimes thought of as an iterator which compared neighbours, didn't. If it behaved as some people wished, then we could simply write
groupBy (<) [3,4,5,6,2,3,4,1,2,1]
and get : [[3,4,5,6],[2,3,4],[1,2],[1]]
Actually ... It works!! But unfortunately this is accidental. The following example doesn't:
groupBy (<)
[5,3,1,2,8,6,3,7,2,5,9]
[[5],[3],[1,2,8,6,3,7,2,5,9]]
This was discovered apparently more than once. Look up
http://brandon.si/code/an-alternative-definition-for-datalistgroupby/
Brandon Simmons gives his alternative definition, which defines its own version of span:
groupBy' :: (a
-> a -> Bool) -> [a] -> [[a]]
groupBy' c [] = []
groupBy' c (a:as) = (a:ys) : groupBy' c zs
where (ys,zs) = spanC a as
spanC _ [] = ([], [])
spanC a' (x:xs)
| a' `c` x = let (ps,qs) = spanC x xs
in (x:ps,qs)
| otherwise = ([], x:xs)
which yields the following result:
groupBy' (<)
[5,3,1,2,8,6,3,7,2,5,9]
[[5],[3],[1,2,8],[6],[3,7],[2,5,9]]
Look also:
https://hackage.haskell.org/package/groupBy-0.1.0.0/docs/Data-List-GroupBy.html
by Donnacha Oisín Kidney (c) 2018; but I didn't verify his variant.
==
Jerzy Karczmarczuk