
On 29 Jul 2004 12:32:19 +0200, Peter Simons
Simon Marlow writes:
split :: (a -> Bool) -> [a] -> [[a]]
tokens :: (a -> Bool) -> [a] -> [[a]]
Unfortunately, neither function would help me solve my \r\n-line-ending case. I need separators that are longer than one "character". I also think the idea of being able to use the full "current prefix" for the decision is important. I can't use these function, because they would, for example, erroneously split the string "abc\ndef".
So far, I like the breakWhere function Ketil proposed best.
I often use an even more generic function: splitter :: ([a] -> (b,[a])) -> [a] -> [b] splitter _ [] = [] splitter f xs = b : splitter f rest where (b,rest) = f xs The name might not be ideal, but the general mechanics of it is pretty nice. /Martin