module EL.Private.Then where
import Prelude hiding (break, span, take, takeWhile, mapM)
import qualified Data.List as List
takeWhile :: (a -> Bool) -> ([a] -> [a]) -> [a] -> [a]
takeWhile _ cont [] = cont []
takeWhile f cont (x:xs)
| f x = x : takeWhile f cont xs
| otherwise = cont (x:xs)
takeWhile1 :: (a -> Bool) -> [a] -> [a]
takeWhile1 f = takeWhile f (List.take 1)
take :: Int -> ([a] -> [a]) -> [a] -> [a]
take _ cont [] = cont []
take n cont (x:xs)
| n <= 0 = cont (x:xs)
| otherwise = x : take (n-1) cont xs
filter :: (a -> Bool) -> (a -> Bool) -> ([a] -> [a]) -> [a] -> [a]
filter f done cont = go
where
go [] = []
go (x:xs)
| done x = cont (x:xs)
| f x = x : go xs
| otherwise = go xs
mapAccumL :: (acc -> x -> (acc, y)) -> acc -> (acc -> [y]) -> [x] -> [y]
mapAccumL f acc cont = go acc
where
go acc [] = cont acc
go acc (x:xs) = y : go acc2 xs
where (acc2, y) = f acc x
break :: (a -> Bool) -> ([a] -> ([a], rest))
-> [a] -> ([a], rest)
break f cont (x:xs)
| f x = cont (x:xs)
| otherwise = let (pre, post) = break f cont xs in (x:pre, post)
break _ cont [] = cont []
span :: (a -> Bool) -> ([a] -> ([a], rest)) -> [a] -> ([a], rest)
span f = break (not . f)
break1 :: (a -> Bool) -> [a] -> ([a], [a])
break1 f = break f (splitAt 1)
mapM :: Monad m => (a -> m b) -> m [b] -> [a] -> m [b]
mapM f cont = go
where
go [] = cont
go (a:as) = do
b <- f a
(b:) <$> go as