varying-0.5.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

Event streams describe things that happen at a specific domain. For example, you can think of the event stream VarT IO Double (Event ()) as an occurrence of () at a specific input of type Double.

For sequencing streams please check out Spline which lets you chain together sequences of event streams using do-notation.

Synopsis

Documentation

data Event a Source

A value of Event () means that an event has occurred and that the result is a (). A value of NoEvent means that an event did not occur.

Event streams (like VarT m a (Event b)) describe events that may occur over varying a (also known as the series of a). Usually a would be some form of time or some user input type.

Constructors

Event a 
NoEvent 

Instances

Monad Event Source 
Functor Event Source 
Applicative Event Source 
Alternative Event Source 
MonadPlus Event Source 
Eq a => Eq (Event a) Source 
Floating a => Floating (Event a) Source 
Fractional a => Fractional (Event a) Source 
Num a => Num (Event a) Source 
Show a => Show (Event a) Source 
Monoid (Event a) Source

Any event is a monoid that responds to mempty with NoEvent. It responds to mappend by always choosing the rightmost event. This means left events are replaced unless the right event is NoEvent.

Transforming event values.

toMaybe :: Event a -> Maybe a Source

Turns an Event into a Maybe.

isEvent :: Event a -> Bool Source

Returns True when the Event contains a sample and False otherwise.

Combining event and value streams

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

Produces values from the first unless the second produces event values and if so, produces the values of those events.

Generating events from value streams

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

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.

onJust :: (Applicative m, Monad m) => VarT m (Maybe a) (Event a) Source

Triggers an `Event a` when the input is `Just a`.

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

Triggers an `Event a` when the input is a unique value.

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

Using multiple streams

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

If the left event stream produces a value, wrap the value in Left and produce that value, else if the right event stream produces a value, wrap the value in Right and produce that value, else inhibit.

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 left 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 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.

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

Never produces any event values.

Switching

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

switchByMode :: (Applicative m, Monad m, Eq b) => VarT m a b -> (b -> VarT m a c) -> VarT m a c Source

Switches using a mode signal. Streams maintain state only for the duration of the mode.

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 value stream v only when an event stream h produces an event. v and h maintain state while cold.