
I have a few functions for operating on lists that take continuations:
-- | Like takeWhile but with a continuation, so you can chain takes without
-- copying.
takeWhileThen :: (a -> Bool) -> ([a] -> [a]) -> [a] -> [a]
takeWhileThen _ _ [] = []
takeWhileThen f cont (x:xs)
| f x = x : takeWhileThen f cont xs
| otherwise = cont (x:xs)
But of course this isn't enough, then I start wanting a takeThen. And
then a filterThen. That makes me think plain explicit recursion would
be clearer, but the problem I have with that is that it has an
imperative feel. What I mean by that is that the result is a product
of the changing state of the recursing function, and it's
non-composable. E.g.
filterUntil start end msgs = go
where
go [] = []
go (m:ms)
| msg_start m >= start = takeWhile ((