module Fold.Shortcut.Run where

import Fold.Shortcut.Type

{-| Fold a listlike container to a single summary result, forcing
    only enough input to satisfy the short-cutting fold -}
run :: ShortcutFold a b -> [a] -> b
run :: forall a b. ShortcutFold a b -> [a] -> b
run ShortcutFold{ Vitality x y
initial :: ()
initial :: Vitality x y
initial, y -> a -> Vitality x y
step :: ()
step :: y -> a -> Vitality x y
step, x -> b
extractDead :: ()
extractDead :: x -> b
extractDead, y -> b
extractLive :: ()
extractLive :: y -> b
extractLive } = Vitality x y -> [a] -> b
go Vitality x y
initial
  where
    go :: Vitality x y -> [a] -> b
go (Alive Will
Tenacious y
x) (a
a : [a]
as)  =  Vitality x y -> [a] -> b
go (y -> a -> Vitality x y
step y
x a
a) [a]
as
    go (Alive Will
Tenacious y
x) []        =  y -> b
extractLive y
x
    go (Alive Will
Ambivalent y
x) [a]
_        =  y -> b
extractLive y
x
    go (Dead x
x)             [a]
_        =  x -> b
extractDead x
x