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
as an occurrence of VarT
IO
Double
(Event
())()
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
means that an event has occurred and that the
result is a Event
()()
. A value of NoEvent
means that an event did not
occur.
Event streams (like
) describe events that may occur
over varying VarT
m a (Event
b)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 |
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
onWhen :: Applicative m => (a -> Bool) -> VarT m a (Event a) Source
Triggers an
when the condition is met.Event
a
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
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 Event
s 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 Event
s 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.
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.