-- | Constructs list from upstream values, discarding them while the predicate holds (and while there are any values left).
-- This function is semantically equivalent to:
--
-- > takeWhile pr >> return ()
--
-- This function is consistent with `Data.Conduit.List.drop`, if you want it
-- to be consistent with `Data.List.drop` instead use:
--
-- > dropWhile pr >> consume
--
-- Or alternatively:
--
-- > ignoreWhile pr =$ consume
--
dropWhile :: Monad m => (a -> Bool) -> C.Sink a m ()
dropWhile pr = loop
    where loop = C.await >>= maybe (return ())
                                   (\val -> if pr val
                                               then loop
                                               else C.leftover val
                                   )
                                   
-- | Ignores the values from upstream while the predicate holds, after that pipes all the values. Complement to `isolateWhile`.
-- Example:
--
-- >>> sourceList [1..10] $= ignoreWhile (< 3) $$ consume
-- [3,4,5,6,7,8,9,10]
dropWhile :: Monad m => (a -> Bool) -> C.Sink a m ()
dropWhile pr = loop
    where loop = C.await >>= maybe (return ())
                                   (\val -> if pr val
                                               then loop
                                               else C.leftover val
                                   )
                                   
-- | Ignores the values from upstream while the predicate holds, after that pipes all the values. Complement to `isolateWhile`.
-- Example:
--
-- >>> sourceList [1..10] $= ignoreWhile (< 3) $$ consume
-- [3,4,5,6,7,8,9,10]
dropWhile pr = loop
    where loop = C.await >>= maybe (return ())
                                   (\val -> if pr val
                                               then loop
                                               else C.leftover val
                                   )
                                   
-- | Ignores the values from upstream while the predicate holds, after that pipes all the values. Complement to `isolateWhile`.
-- Example:
--
-- >>> sourceList [1..10] $= ignoreWhile (< 3) $$ consume
-- [3,4,5,6,7,8,9,10]