Yampa-0.13.3: Elegant Functional Reactive Programming Language for Hybrid Systems
Copyright(c) Antony Courtney and Henrik Nilsson Yale University 2003
LicenseBSD-style (see the LICENSE file in the distribution)
Maintainerivan.perez@keera.co.uk
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

FRP.Yampa.Conditional

Description

Apply SFs only under certain conditions.

Synopsis

Documentation

provided :: (a -> Bool) -> SF a b -> SF a b -> SF a b Source #

Runs a signal function only when a given predicate is satisfied, otherwise runs the other signal function.

This is similar to ArrowChoice, except that this resets the SFs after each transition.

For example, the following integrates the incoming input numbers, using one integral if the numbers are even, and another if the input numbers are odd. Note how, every time we "switch", the old value of the integral is discarded.

>>> embed (provided (even . round) integral integral) (deltaEncode 1 [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2 :: Double])
[0.0,1.0,2.0,0.0,2.0,4.0,0.0,1.0,2.0,0.0,2.0,4.0]

pause :: b -> SF a Bool -> SF a b -> SF a b Source #

Given a value in an accumulator (b), a predicate signal function (sfC), and a second signal function (sf), pause will produce the accumulator b if sfC input is True, and will transform the signal using sf otherwise. It acts as a pause with an accumulator for the moments when the transformation is paused.