module Control.Wire.Trans.Simple
(
ifW
)
where
import Control.Arrow
import Control.Monad
import Control.Wire.Wire
import Data.Monoid
import Prelude hiding ((.), id)
ifW ::
(Monad m, Monoid e)
=> Wire e m a Bool
-> Wire e m a b
-> Wire e m a b
-> Wire e m a b
ifW = ifW' 0 0
where
ifW' !tx !ty wp' wx' wy' =
mkGen $ \dt x' -> do
(mb, wp) <- stepWire wp' dt x'
case mb of
Left ex -> return (Left ex, ifW' (tx + dt) (ty + dt) wp wx' wy')
Right b ->
if b
then liftM (second (\wx -> ifW' 0 (ty + dt) wp wx wy')) $
stepWire wx' (tx + dt) x'
else liftM (second (ifW' (tx + dt) 0 wp wx')) $
stepWire wy' (ty + dt) x'