reactivity-0.3.2.4: An alternate implementation of push-pull FRP.

Safe HaskellTrustworthy
LanguageHaskell98

FRP.Reactivity.Combinators

Contents

Description

A different presentation of functional reactive programming, based on the Reactive library on Hackage. Push-pull FRP is due to Conal Elliott. The functionals here are directly based on those from Reactive.

Synopsis

Derived event combinators

tick :: EventStream e => POSIXTime -> POSIXTime -> e POSIXTime Source #

A convenience to generate a tick on a regular interval.

untilE :: EventStream e => e t -> e u -> e t Source #

This functional can be used to terminate an event early.

eitherOf :: (Functor e, MonadPlus e) => e t -> e u -> e (Either t u) Source #

holdE :: EventStream e => e t -> e u -> u -> e (t, u) Source #

Give the event times of e, but latching onto the ticks of e2. Prior to e2 ticking, gives x.

zipE :: EventStream f => f t -> t -> f t1 -> t1 -> f (t, t1) Source #

simultE :: EventStream e => e t -> e u -> e (t, Maybe u) Source #

Pair values from e to simultaneous occurrences from a. Multiple occurrences are paired up as with zip. Excess occurrences from a are discarded, while excess WithAtoms falses atomsoccurrences from e are paired with 'N(E simultE #-)

intersectE :: EventStream f => f (a -> b) -> f a -> f b Source #

differenceE :: EventStream f => f b -> f b1 -> f b Source #

Set-theoretical operations on event streams

unionE :: (EventStream e, Monoid t) => e t -> e t -> e t Source #

filterE :: (Alternative m, Monad m) => (b -> Bool) -> m b -> m b Source #

justE :: (Alternative f, Monad f) => f (Maybe b) -> f b Source #

duplicateE :: EventStream m => m a -> m (m a) Source #

withPrev :: EventStream f => f t -> f (t, t) Source #

calmE :: EventStream f => f b -> f b Source #

Calms an event stream so that only one event occurs at a given time.

count :: (EventStream e, Num t1) => e t -> e (t, t1) Source #

takeE :: (EventStream e, Num n, Ord n) => n -> e t -> e t Source #

dropE :: (EventStream f, Ord b1, Num b1) => b1 -> f b -> f b Source #

Event versions of drop and take.

once :: EventStream e => e t -> e t Source #

everyNth :: (EventStream e, Num n, Ord n) => n -> e t -> e t Source #

slowE :: EventStream m => POSIXTime -> m b -> m b Source #

rests :: EventStream e => e a -> e t -> e (t, e a) Source #

Get the remainder events of e looking forward from particular occurrences in a

startAt :: EventStream m => m b -> m a -> m b Source #

Waits until a ticks before it starts ticking.

splitE :: EventStream e => e t -> e u -> e (e t) Source #

Divides e into chunks based on the ticks of a, and returns those chunks in an event stream. The occurrences of e prior to the first occurrence of a are omitted.

Reactive behaviors

data Behavior e t Source #

Instances

Functor e => Functor (Behavior e) Source # 

Methods

fmap :: (a -> b) -> Behavior e a -> Behavior e b #

(<$) :: a -> Behavior e b -> Behavior e a #

EventStream e => Applicative (Behavior e) Source # 

Methods

pure :: a -> Behavior e a #

(<*>) :: Behavior e (a -> b) -> Behavior e a -> Behavior e b #

(*>) :: Behavior e a -> Behavior e b -> Behavior e b #

(<*) :: Behavior e a -> Behavior e b -> Behavior e a #

EventStream e => Alternative (Behavior e) Source # 

Methods

empty :: Behavior e a #

(<|>) :: Behavior e a -> Behavior e a -> Behavior e a #

some :: Behavior e a -> Behavior e [a] #

many :: Behavior e a -> Behavior e [a] #

(EventStream e, Monoid t) => Monoid (Behavior e t) Source # 

Methods

mempty :: Behavior e t #

mappend :: Behavior e t -> Behavior e t -> Behavior e t #

mconcat :: [Behavior e t] -> Behavior e t #

extractB :: Behavior t t1 -> t1 Source #

switcher :: EventStream e => Behavior e t -> e (Behavior e t) -> Behavior e t Source #

stepper :: Functor e => t -> e t -> Behavior e t Source #

snapshot :: EventStream f => f t -> Behavior f t1 -> f (t, t1) Source #

flipFlop :: MonadPlus e => e b -> e b1 -> Behavior e Bool Source #

history :: EventStream e => Double -> Behavior e t -> Behavior e (POSIXTime -> t) Source #

Keep a history of t seconds as a "moving window" -- giving values for the behavior, t seconds prior to the current time. Outside of this moving window, gives a constant behavior.

This functional should be enough for all "history-dependent" behaviors -- there should be some t which is a constant bound on a behavior's history, in order to conserve memory.

scanB :: EventStream e => Behavior e (t -> e t) -> t -> e t Source #

A scan for behaviors.

delayB :: EventStream e => POSIXTime -> Behavior e c -> Behavior e c Source #

Delay by t seconds before continuing as the behavior.

slow :: EventStream e => POSIXTime -> Behavior e c -> Behavior e c Source #

Slow down the behavior by a factor of x.

monoid :: (EventStream e, Monoid t) => e (Behavior e t) -> Behavior e t Source #

Collect the event occurrences and add them together into a single behavior, using a monoid.

throttle :: EventStream e => Double -> e t -> Behavior e (Maybe t) Source #

Each event occurrence casts a shadow for t seconds in the behavior.

sumE :: Num t => Event t -> Event t Source #

derivative :: (EventStream e, Real t, Fractional t) => Behavior e t -> Behavior e t Source #

Estimate the derivative of a behavior.

supersample :: (EventStream e, Real t, Fractional t) => Double -> Behavior e t -> e (POSIXTime, t) Source #

Adaptively supersample a behavior.

integral :: (Real t, Fractional t) => Double -> Behavior Event t -> Behavior Event t Source #

Integral of behaviors

threshold :: (EventStream e, Real t, Fractional t) => Double -> Behavior e t -> t -> e Bool Source #

Given a differentiable behavior, find the times at which a certain value could be found. The result is an event which ticks when (an approximation of) the value is encountered.