[Haskell-cafe] How to split this string.
Christian.Maeder at dfki.de
Thu Jan 5 13:16:30 CET 2012
Am 05.01.2012 13:04, schrieb Steve Horne:
> I was going to accuse you of cheating - who says there's a spare value
> to use? - but you seem to be using Maybe, so well played.
> You're also using unfoldr, which I really must play with a bit - I don't
> really have a feel for how unfolding works ATM.
You may prefer another variant of unfoldr (without Maybe):
unfoldr' :: ([b] -> (a, [b])) -> [b] -> [a]
unfoldr' f l = if null l then  else
let (a, r) = f l in a : unfoldr' f r
split' :: (a -> Bool) -> (a -> Bool) -> [a] -> [[a]]
split' e p = unfoldr' $ break' e p
P.S. my break' function fails for "\r\r\n" (as the first char escapes
the second and the second no longer the third)
More information about the Haskell-Cafe