{-# LANGUAGE Arrows #-}
{-# LANGUAGE RecordWildCards #-}
module LiveCoding.Cell.Util where
import Control.Arrow
import Data.Data (Data)
import LiveCoding.Cell
import LiveCoding.Cell.Feedback
sumFrom :: Monad m => Integer -> Cell m Integer Integer
sumFrom n0 = feedback n0 $ proc (n, acc) -> returnA -< (acc, acc + n)
count :: Monad m => Cell m a Integer
count = arr (const 1) >>> sumC
foldC :: (Data b, Monad m) => (a -> b -> b) -> b -> Cell m a b
foldC step cellState = Cell { .. }
where
cellStep b a = let b' = step a b in return (b, b')