iteratee takeWhile - coule functions for analogy with lists
Michael Baikov
manpacket at gmail.com
Tue Sep 6 05:35:33 BST 2011
I think this will fit nicely in Data.Iteratee.ListLike. This function
can cause some troubles when used improperly, but it's no more
harmfull than stream2stream or stream2list which we already have.
-- | Take all elements while predicate is true. Make sure that it will
encounter element where predicate is
-- false or protect your iteratee with enumWith.
-- | Takes an element predicate and returns the (possibly empty)
prefix of the stream. All characters
-- in the string will satisfy the character predicate. If the stream
is not terminated, the first character of the
-- remaining stream will not satisfy the predicate.
-- The analogue of @List.takeWhile@, see also @break@ and @takeWhileE@
takeWhile :: (ListLike s el, Monad m) => (el -> Bool) -> Iteratee s m s
takeWhile = break . not
-- |Takes an element predicate and an iteratee, running the iteratee
-- on all elements of the stream while the predicate is met. This is
preferred to
-- @takeWhile at .
takeWhileE
:: (Monad m, LL.ListLike s el, NullPoint s)
=> (el -> Bool)
-> Enumeratee s s m a
takeWhileE = breakE . not
More information about the Iteratee
mailing list