module Penny.Lincoln.Family.Family where
import qualified Data.Functor.Identity as I
data Family p c =
Family { parent :: p
, child1 :: c
, child2 :: c
, children :: [c] }
deriving (Eq, Show)
mapChildrenM ::
Monad m
=> (a -> m b)
-> Family p a
-> m (Family p b)
mapChildrenM f (Family p c1 c2 cs) = do
c1' <- f c1
c2' <- f c2
cs' <- mapM f cs
return $ Family p c1' c2' cs'
mapChildren ::
(a -> b)
-> Family p a
-> Family p b
mapChildren f fam = I.runIdentity (mapChildrenM f' fam) where
f' = return . f
mapParentM ::
Monad m
=> (a -> m b)
-> Family a c
-> m (Family b c)
mapParentM f (Family p c1 c2 cs) = do
p' <- f p
return $ Family p' c1 c2 cs
mapParent :: (a -> b) -> Family a c -> Family b c
mapParent f fam = I.runIdentity (mapParentM f' fam) where
f' = return . f