{-# LANGUAGE FunctionalDependencies, Safe #-}
module Dep.Class.Walkable (
Walkable(step, walk, allStep, allWalk, stepValues, stepValues', allStepValues, allStepValues', walkValues', allWalkValues)
) where
import Dep.Utils(toList')
import Data.Foldable(toList)
class Walkable f step | f -> step where
step
:: f a
-> step
-> f a
step f a
item step
stp = f a -> [step] -> f a
forall (f :: * -> *) step (g :: * -> *) a.
(Walkable f step, Foldable g) =>
f a -> g step -> f a
walk f a
item [step
stp]
stepValues' :: Foldable f
=> f a
-> step
-> [a]
-> [a]
stepValues' f a
item step
stp = f a -> [a] -> [a]
forall (f :: * -> *) a. Foldable f => f a -> [a] -> [a]
toList' (f a -> step -> f a
forall (f :: * -> *) step a. Walkable f step => f a -> step -> f a
step f a
item step
stp)
stepValues :: Foldable f
=> f a
-> step
-> [a]
stepValues f a
item step
stp = f a -> step -> [a] -> [a]
forall (f :: * -> *) step a.
(Walkable f step, Foldable f) =>
f a -> step -> [a] -> [a]
stepValues' f a
item step
stp []
allStep :: Functor g
=> g (f a)
-> step
-> g (f a)
allStep = (step -> g (f a) -> g (f a)) -> g (f a) -> step -> g (f a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((f a -> f a) -> g (f a) -> g (f a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((f a -> f a) -> g (f a) -> g (f a))
-> (step -> f a -> f a) -> step -> g (f a) -> g (f a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> step -> f a) -> step -> f a -> f a
forall a b c. (a -> b -> c) -> b -> a -> c
flip f a -> step -> f a
forall (f :: * -> *) step a. Walkable f step => f a -> step -> f a
step)
allStepValues' :: (Foldable f, Foldable g)
=> g (f a)
-> step
-> [a]
-> [a]
allStepValues' g (f a)
items step
stp [a]
tl = (f a -> [a] -> [a]) -> [a] -> g (f a) -> [a]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (f a -> [a] -> [a]
forall (f :: * -> *) a. Foldable f => f a -> [a] -> [a]
toList' (f a -> [a] -> [a]) -> (f a -> f a) -> f a -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (f a -> step -> f a
forall (f :: * -> *) step a. Walkable f step => f a -> step -> f a
`step` step
stp)) [a]
tl g (f a)
items
allStepValues :: (Foldable f, Foldable g)
=> g (f a)
-> step
-> [a]
allStepValues g (f a)
items step
stp = g (f a) -> step -> [a] -> [a]
forall (f :: * -> *) step (g :: * -> *) a.
(Walkable f step, Foldable f, Foldable g) =>
g (f a) -> step -> [a] -> [a]
allStepValues' g (f a)
items step
stp []
walk :: Foldable g
=> f a
-> g step
-> f a
walk = (f a -> step -> f a) -> f a -> g step -> f a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl f a -> step -> f a
forall (f :: * -> *) step a. Walkable f step => f a -> step -> f a
step
walkValues' :: (Foldable f, Foldable g)
=> f a
-> g step
-> [a]
-> [a]
walkValues' f a
x = f a -> [a] -> [a]
forall (f :: * -> *) a. Foldable f => f a -> [a] -> [a]
toList' (f a -> [a] -> [a]) -> (g step -> f a) -> g step -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f a -> g step -> f a
forall (f :: * -> *) step (g :: * -> *) a.
(Walkable f step, Foldable g) =>
f a -> g step -> f a
walk f a
x
allWalkValues :: (Foldable f, Foldable g, Functor g, Foldable h)
=> g (f a)
-> h step
-> [a]
allWalkValues g (f a)
x = (f a -> [a]) -> g (f a) -> [a]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (g (f a) -> [a]) -> (h step -> g (f a)) -> h step -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g (f a) -> h step -> g (f a)
forall (f :: * -> *) step (g :: * -> *) (h :: * -> *) a.
(Walkable f step, Functor g, Foldable h) =>
g (f a) -> h step -> g (f a)
allWalk g (f a)
x
allWalk :: (Functor g, Foldable h)
=> g (f a)
-> h step
-> g (f a)
allWalk = (g (f a) -> step -> g (f a)) -> g (f a) -> h step -> g (f a)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl g (f a) -> step -> g (f a)
forall (f :: * -> *) step (g :: * -> *) a.
(Walkable f step, Functor g) =>
g (f a) -> step -> g (f a)
allStep
{-# MINIMAL step | walk #-}