module Data.List.Reverse.StrictElement where
import Data.Tuple.HT (mapFst, mapSnd, forcePair, )
import Prelude hiding (dropWhile, takeWhile, span, )
dropWhile :: (a -> Bool) -> [a] -> [a]
dropWhile :: forall a. (a -> Bool) -> [a] -> [a]
dropWhile a -> Bool
p =
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a
x [a]
xs -> if a -> Bool
p a
x Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
xs then [] else a
xforall a. a -> [a] -> [a]
:[a]
xs) []
takeWhile :: (a -> Bool) -> [a] -> [a]
takeWhile :: forall a. (a -> Bool) -> [a] -> [a]
takeWhile a -> Bool
p =
forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
(\a
x (Bool, [a])
xys ->
(if a -> Bool
p a
x Bool -> Bool -> Bool
&& forall a b. (a, b) -> a
fst (Bool, [a])
xys then forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd (a
xforall a. a -> [a] -> [a]
:) else forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst (forall a b. a -> b -> a
const Bool
False)) (Bool, [a])
xys)
(Bool
True, [])
span :: (a -> Bool) -> [a] -> ([a], [a])
span :: forall a. (a -> Bool) -> [a] -> ([a], [a])
span a -> Bool
p =
forall a b. (a, b) -> (a, b)
forcePair forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr
(\a
x ([a], [a])
xys ->
(if a -> Bool
p a
x Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null (forall a b. (a, b) -> a
fst ([a], [a])
xys) then forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd else forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst) (a
xforall a. a -> [a] -> [a]
:) ([a], [a])
xys)
([], [])