module Data.List.Extended
    ( module Data.List
    , breakWhen
    ) where

import           Data.List

-- | Like 'break', but can act on the entire tail of the list.
breakWhen :: ([a] -> Bool) -> [a] -> ([a], [a])
breakWhen :: forall a. ([a] -> Bool) -> [a] -> ([a], [a])
breakWhen [a] -> Bool
predicate = [a] -> [a] -> ([a], [a])
go []
  where
    go :: [a] -> [a] -> ([a], [a])
go [a]
buf []                = (forall a. [a] -> [a]
reverse [a]
buf, [])
    go [a]
buf (a
x : [a]
xs)
        | [a] -> Bool
predicate (a
x forall a. a -> [a] -> [a]
: [a]
xs) = (forall a. [a] -> [a]
reverse [a]
buf, a
x forall a. a -> [a] -> [a]
: [a]
xs)
        | Bool
otherwise          = [a] -> [a] -> ([a], [a])
go (a
x forall a. a -> [a] -> [a]
: [a]
buf) [a]
xs