module Lseed.Data.Functions where
import Lseed.Data
import Data.Monoid
plantPieceLengths :: Plant a -> Plant Double
plantPieceLengths (Plant _ len ang ut ps) =
Plant len len ang ut (map plantPieceLengths ps)
plantLength :: Plant a -> Double
plantLength = plantTotalSum . plantPieceLengths
plantTotalSum :: Plant Double -> Double
plantTotalSum = getSum . pData . subPieceAccumulate . fmap Sum
subPieceAccumulate :: Monoid m => Plant m -> Plant m
subPieceAccumulate p = go p
where go (Plant x len ang ut ps) = let ps' = map go ps
x' = x `mappend` (mconcat $ map pData ps')
in Plant x' len ang ut ps'
mapGarden :: (Planted a -> Planted b) -> Garden a -> Garden b
mapGarden = map
zipWithGarden :: (Planted a -> x -> Planted b) -> Garden a -> [x] -> Garden b
zipWithGarden = zipWith
mapPlanted :: (Plant a -> Plant b) -> Planted a -> Planted b
mapPlanted f planted = planted { phenotype = f (phenotype planted) }