module Data.List.Extra.Drop where
dropWhile1 :: (a -> Bool) -> [a] -> [a]
dropWhile1 :: forall a. (a -> Bool) -> [a] -> [a]
dropWhile1 a -> Bool
_ [] = []
dropWhile1 a -> Bool
p (a
x:[a]
xs)
| a -> Bool
p a
x = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile a -> Bool
p [a]
xs
| Bool
otherwise = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs
dropWhileEnd1 :: (a -> Bool) -> [a] -> [a]
dropWhileEnd1 :: forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd1 a -> Bool
p = [a] -> [a]
go
where
go :: [a] -> [a]
go = \case
[] -> []
a
x:[a]
xs -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: if a -> Bool
p a
x then [a] -> [a] -> [a]
go' [] [a]
xs else [a] -> [a]
go [a]
xs
go' :: [a] -> [a] -> [a]
go' [a]
acc = \case
[] -> []
a
x:[a]
xs -> if a -> Bool
p a
x then [a] -> [a] -> [a]
go' (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
acc) [a]
xs else [a] -> [a]
forall a. [a] -> [a]
reverse [a]
acc [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a]
go [a]
xs