varying-0.7.0.3: FRP through value streams and monadic splines.

Copyright(c) 2015 Schell Scivally
LicenseMIT
MaintainerSchell Scivally <schell.scivally@synapsegroup.com>
Safe HaskellNone
LanguageHaskell2010

Control.Varying.Event

Contents

Description

An event stream is simply a stream of Maybe a. This kind of stream is considered to be only defined at those occurances of Just a. Events describe things that happen at a specific time, place or any collection of inputs.

For example, you can think of the event stream VarT IO Double (Event ()) as an occurrence of () at a specific value of Double. It is possible that this Double is time, or it could be the number of ice cream sandwiches eaten by a particular cat.

In varying we use event streams to dynamically update the network while it is running. For more info on switching and sequencing streams with events please check out Spline, which lets you chain together sequences of values and events using a familiar do-notation.

Synopsis

Event constructors (synonyms of Maybe)

event :: a -> Event a Source #

A synonym for the Maybe constructor Just.

noevent :: Event a Source #

A synonym for the Maybe constructor Nothing.

Generating events from value streams

use :: (Functor f, Functor e) => a -> f (e b) -> f (e a) Source #

use :: Monad m => b -> VarT m a (Event x) -> VarT m a (Event b)

Populates a varying Event with a value. This is meant to be used with the various on... event triggers. For example, use 1 onTrue produces values of Event 1 when the input value is True.

onTrue :: (Applicative m, Monad m) => VarT m Bool (Event ()) Source #

Triggers an Event () when the input value is True.

use b onTrue :: Monad m => VarT m Bool (Event b)

onUnique :: (Applicative m, Monad m, Eq a) => VarT m a (Event a) Source #

Triggers an Event a when the input is distinct from the previous input.

use b onUnique :: (Eq x, Monad m) => VarT m x (Event b)

onWhen :: Applicative m => (a -> Bool) -> VarT m a (Event a) Source #

Triggers an Event a when the condition is met.

Folding and gathering event streams

foldStream :: Monad m => (a -> t -> a) -> a -> VarT m (Event t) a Source #

Like a left fold over all the stream's produced values.

startingWith :: (Applicative m, Monad m) => a -> VarT m (Event a) a Source #

Produces the given value until the input events produce a value, then produce that value until a new input event produces. This always holds the last produced value, starting with the given value.

time >>> after 3 >>> startingWith 0

startWith :: (Applicative m, Monad m) => a -> VarT m (Event a) a Source #

Produces the given value until the input events produce a value, then produce that value until a new input event produces. This always holds the last produced value, starting with the given value.

time >>> after 3 >>> startingWith 0

Combining multiple event streams

bothE :: (Applicative m, Monad m) => (a -> b -> c) -> VarT m a (Event a) -> VarT m a (Event b) -> VarT m a (Event c) Source #

Combine two Event streams. Produces an event only when both streams proc at the same time.

anyE :: (Applicative m, Monad m) => [VarT m a (Event b)] -> VarT m a (Event b) Source #

Combine two Event streams and produce an Event any time either stream produces. In the case that both streams produce, this produces the Event of the leftmost stream.

List-like operations on event streams

filterE :: (Applicative m, Monad m) => (b -> Bool) -> VarT m a (Event b) -> VarT m a (Event b) Source #

Inhibit all Events that don't pass the predicate.

takeE :: (Applicative m, Monad m) => Int -> VarT m a (Event b) -> VarT m a (Event b) Source #

Stream through some number of successful Events and then inhibit forever.

dropE :: (Applicative m, Monad m) => Int -> VarT m a (Event b) -> VarT m a (Event b) Source #

Inhibit the first n occurences of an Event.

Primitive event streams

once :: (Applicative m, Monad m) => b -> VarT m a (Event b) Source #

Produce the given event value once and then inhibit forever.

always :: (Applicative m, Monad m) => b -> VarT m a (Event b) Source #

Produces Events with the initial value forever.

always e = pure (Event e)

never :: (Applicative m, Monad m) => VarT m b (Event c) Source #

Never produces any Event values.

never = pure Nothing

before :: (Applicative m, Monad m, Num t, Ord t) => t -> VarT m t (Event t) Source #

Emits events before accumulating t of input dt. Note that as soon as we have accumulated >= t we stop emitting events and therefore an event will never be emitted exactly at time == t.

after :: (Applicative m, Monad m, Num t, Ord t) => t -> VarT m t (Event t) Source #

Emits events after t input has been accumulated. Note that event emission is not guaranteed to begin exactly at t, since it depends on the input.

Bubbling

onlyWhen Source #

Arguments

:: (Applicative m, Monad m) 
=> VarT m a b

v - The value stream

-> (a -> Bool)

f - The predicate to run on v's input values.

-> VarT m a (Event b) 

Produce Events of a value stream v only when its input value passes a predicate f. v maintains state while cold.

onlyWhenE Source #

Arguments

:: (Applicative m, Monad m) 
=> VarT m a b

v - The value stream

-> VarT m a (Event c)

h - The event stream

-> VarT m a (Event b) 

Produce events of a stream v only when an event stream h produces an event. v and h maintain state while cold.