module Data.List.Extended
( module Data.List
, breakWhen
) where
import Data.List
breakWhen :: ([a] -> Bool) -> [a] -> ([a], [a])
breakWhen :: ([a] -> Bool) -> [a] -> ([a], [a])
breakWhen [a] -> Bool
predicate = [a] -> [a] -> ([a], [a])
go []
where
go :: [a] -> [a] -> ([a], [a])
go [a]
buf [] = ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
buf, [])
go [a]
buf (a
x : [a]
xs)
| [a] -> Bool
predicate (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs) = ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
buf, a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs)
| Bool
otherwise = [a] -> [a] -> ([a], [a])
go (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
buf) [a]
xs