{-# LANGUAGE MultiParamTypeClasses #-}

module Data.Diverse.AFoldable where

-- | Constrained Foldable for a specified type instead for all types.
class AFoldable t a where
     afoldr :: (a -> b -> b) -> b -> t a -> b

afoldl' :: AFoldable t a => (b -> a -> b) -> b -> t a -> b
afoldl' :: forall (t :: * -> *) a b.
AFoldable t a =>
(b -> a -> b) -> b -> t a -> b
afoldl' b -> a -> b
f b
z0 t a
xs = forall (t :: * -> *) a b.
AFoldable t a =>
(a -> b -> b) -> b -> t a -> b
afoldr forall {b}. a -> (b -> b) -> b -> b
f' forall a. a -> a
id t a
xs b
z0
  where f' :: a -> (b -> b) -> b -> b
f' a
x b -> b
k b
z = b -> b
k forall a b. (a -> b) -> a -> b
$! b -> a -> b
f b
z a
x