Copyright | (c) 2015 Schell Scivally |
---|---|
License | MIT |
Maintainer | Schell Scivally <schell.scivally@synapsegroup.com> |
Safe Haskell | None |
Language | Haskell2010 |
Event
streams describe things that happen at a specific domain.
For example, you can think of the event stream
Var 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.
- data Event a
- toMaybe :: Event a -> Maybe a
- isEvent :: Event a -> Bool
- orE :: (Applicative m, Monad m) => Var m a b -> Var m a (Event b) -> Var m a b
- use :: (Functor f, Functor e) => a -> f (e b) -> f (e a)
- onTrue :: (Applicative m, Monad m) => Var m Bool (Event ())
- onJust :: (Applicative m, Monad m) => Var m (Maybe a) (Event a)
- onUnique :: (Applicative m, Monad m, Eq a) => Var m a (Event a)
- onWhen :: Applicative m => (a -> Bool) -> Var m a (Event a)
- foldStream :: Monad m => (a -> t -> a) -> a -> Var m (Event t) a
- startingWith :: (Applicative m, Monad m) => a -> Var m (Event a) a
- startWith :: (Applicative m, Monad m) => a -> Var m (Event a) a
- filterE :: (Applicative m, Monad m) => (b -> Bool) -> Var m a (Event b) -> Var m a (Event b)
- takeE :: (Applicative m, Monad m) => Int -> Var m a (Event b) -> Var m a (Event b)
- dropE :: (Applicative m, Monad m) => Int -> Var m a (Event b) -> Var m a (Event b)
- once :: (Applicative m, Monad m) => b -> Var m a (Event b)
- always :: (Applicative m, Monad m) => b -> Var m a (Event b)
- never :: (Applicative m, Monad m) => Var m b (Event c)
- switchByMode :: (Applicative m, Monad m, Eq b) => Var m a b -> (b -> Var m a c) -> Var m a c
- onlyWhen :: (Applicative m, Monad m) => Var m a b -> (a -> Bool) -> Var m a (Event b)
- onlyWhenE :: (Applicative m, Monad m) => Var m a b -> Var m a (Event c) -> Var m a (Event b)
Documentation
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 Var 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.
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.
Combining event and value streams
orE :: (Applicative m, Monad m) => Var m a b -> Var m a (Event b) -> Var 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) => Var m Bool (Event ()) Source
Triggers an `Event ()` when the input value is True.
onJust :: (Applicative m, Monad m) => Var m (Maybe a) (Event a) Source
Triggers an `Event a` when the input is `Just a`.
onUnique :: (Applicative m, Monad m, Eq a) => Var m a (Event a) Source
Triggers an `Event a` when the input is a unique value.
onWhen :: Applicative m => (a -> Bool) -> Var 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 -> Var m (Event t) a Source
Like a left fold over all the stream's produced values.
startingWith :: (Applicative m, Monad m) => a -> Var 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 -> Var 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
List-like operations on event streams
filterE :: (Applicative m, Monad m) => (b -> Bool) -> Var m a (Event b) -> Var m a (Event b) Source
Inhibit all events that don't pass the predicate.
takeE :: (Applicative m, Monad m) => Int -> Var m a (Event b) -> Var m a (Event b) Source
Stream through some number of successful events and then inhibit forever.
dropE :: (Applicative m, Monad m) => Int -> Var m a (Event b) -> Var m a (Event b) Source
Inhibit the first n occurences of an event.
Primitive event streams
once :: (Applicative m, Monad m) => b -> Var m a (Event b) Source
Produce the given value once and then inhibit forever.
always :: (Applicative m, Monad m) => b -> Var m a (Event b) Source
Produces events with the initial value forever.
Switching
switchByMode :: (Applicative m, Monad m, Eq b) => Var m a b -> (b -> Var m a c) -> Var m a c Source
Switches using a mode signal. Streams maintain state only for the duration of the mode.