module Fold.Nonempty.Run where
import Fold.Nonempty.Type
import Data.List.NonEmpty (NonEmpty ((:|)))
import Prelude (($!))
import qualified Data.Foldable as F
run :: NonemptyFold a b -> NonEmpty a -> b
run :: forall a b. NonemptyFold a b -> NonEmpty a -> b
run NonemptyFold{ a -> x
initial :: ()
initial :: a -> x
initial, x -> a -> x
step :: ()
step :: x -> a -> x
step, x -> b
extract :: ()
extract :: x -> b
extract } (a
z :| [a]
as) =
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr forall {b}. a -> (x -> b) -> x -> b
cons x -> b
extract [a]
as (a -> x
initial a
z)
where
cons :: a -> (x -> b) -> x -> b
cons a
a x -> b
k x
x = x -> b
k forall a b. (a -> b) -> a -> b
$! x -> a -> x
step x
x a
a