module Fold.Effectful.Run where
import Fold.Effectful.Type
import Control.Monad (Monad)
import Data.Foldable (Foldable)
import Prelude (($!))
import qualified Data.Foldable as F
run :: Foldable f => Monad m => EffectfulFold m a b -> f a -> m b
run :: forall (f :: * -> *) (m :: * -> *) a b.
(Foldable f, Monad m) =>
EffectfulFold m a b -> f a -> m b
run EffectfulFold{ m x
initial :: ()
initial :: m x
initial, x -> a -> m x
step :: ()
step :: x -> a -> m x
step, x -> m b
extract :: ()
extract :: x -> m b
extract } f a
as0 = do
x
x0 <- m x
initial
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr (\a
a x -> m b
k x
x -> do{ x
x' <- x -> a -> m x
step x
x a
a; x -> m b
k forall a b. (a -> b) -> a -> b
$! x
x' }) x -> m b
extract f a
as0 forall a b. (a -> b) -> a -> b
$! x
x0