{-# LANGUAGE GADTSyntax, NoMonoLocalBinds #-}

module Midair.Handy (
     Fx(..)
   , runFx

   , printFlow
   ) where

import Midair.Core

-- | Representation of side-effecting actions. Usually the final result of
--   the FRP graph
data Fx a where
   Fx_Void :: IO () -> Fx a
   Fx_Return :: IO a -> Fx a

runFx :: Fx a -> IO (Maybe a)
runFx (Fx_Void action) = do
   () <- action
   return Nothing
runFx (Fx_Return action) = Just <$> action

-- | Handy for developing
printFlow :: Show a => SFlow a (Fx b)
printFlow = sMap (Fx_Void . print)