edit - Sorry, I did not read the question. Hope this new answer will do what you want.
> List.groupBy (\xy -> y /= ' ') "The quick brown fox jumped over the lazy dogs." ["The"," quick"," brown"," fox"," jumped"," over"," the"," lazy"," dogs."]
The groupBy library groupBy takes a predicate function that tells you if you add the next element, y, to the previous list, which starts with x or starts a new list.
In this case, we donโt care where the current list started, we only want to start a new list (i.e. make the predicate evaluated as false) when the next element, y, is space.
change
Nm indicates that handling multiple spaces is incorrect. In this case, you can switch to Data.List.HT , which has the semantics you want.
> import Data.List.HT as HT > HT.groupBy (\xy -> y /= ' ' || x == ' ') "abcd" ["a"," b"," c"," d"]
another semantics that does this job is that x is the last element of the previous list (you can add y or create a new list).
source share