{-# LANGUAGE Arrows #-}
{-# LANGUAGE RecordWildCards #-}
module LiveCoding.Cell.Util where
import Control.Arrow
import Control.Monad.IO.Class
import Data.Data (Data)
import Data.Time.Clock
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')
printTime :: MonadIO m => String -> m ()
printTime msg = liftIO $ putStrLn =<< ((take 8 msg) ++) . show <$> getCurrentTime
printTimeC :: MonadIO m => String -> Cell m () ()
printTimeC msg = constM $ printTime msg