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
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.
- data Event a
- toMaybe :: Event a -> Maybe a
- isEvent :: Event a -> Bool
- orE :: (Applicative m, Monad m) => VarT m a b -> VarT m a (Event b) -> VarT m a b
- use :: (Functor f, Functor e) => a -> f (e b) -> f (e a)
- onTrue :: (Applicative m, Monad m) => VarT m Bool (Event ())
- onJust :: (Applicative m, Monad m) => VarT m (Maybe a) (Event a)
- onUnique :: (Applicative m, Monad m, Eq a) => VarT m a (Event a)
- onWhen :: Applicative m => (a -> Bool) -> VarT m a (Event a)
- foldStream :: Monad m => (a -> t -> a) -> a -> VarT m (Event t) a
- startingWith :: (Applicative m, Monad m) => a -> VarT m (Event a) a
- startWith :: (Applicative m, Monad m) => a -> VarT m (Event a) a
- eitherE :: (Applicative m, Monad m) => VarT m a (Event b) -> VarT m a (Event c) -> VarT m a (Event (Either b c))
- anyE :: (Applicative m, Monad m) => [VarT m a (Event b)] -> VarT m a (Event b)
- filterE :: (Applicative m, Monad m) => (b -> Bool) -> VarT m a (Event b) -> VarT m a (Event b)
- takeE :: (Applicative m, Monad m) => Int -> VarT m a (Event b) -> VarT m a (Event b)
- dropE :: (Applicative m, Monad m) => Int -> VarT m a (Event b) -> VarT m a (Event b)
- once :: (Applicative m, Monad m) => b -> VarT m a (Event b)
- always :: (Applicative m, Monad m) => b -> VarT m a (Event b)
- never :: (Applicative m, Monad m) => VarT m b (Event c)
- andThenWith :: (Applicative m, Monad m) => VarT m a (Event b) -> (Event b -> VarT m a (Event b)) -> VarT m a (Event b)
- switchByMode :: (Applicative m, Monad m, Eq b) => VarT m a b -> (b -> VarT m a c) -> VarT m a c
- onlyWhen :: (Applicative m, Monad m) => VarT m a b -> (a -> Bool) -> VarT m a (Event b)
- onlyWhenE :: (Applicative m, Monad m) => VarT m a b -> VarT m a (Event c) -> VarT 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 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.
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) => 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
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.
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.