Safe Haskell | Safe-Infered |
---|
Generalization of the Sodium API to allow for parallel processing.
- class (Applicative (Reactive r), Monad (Reactive r), MonadFix (Reactive r), Functor (Event r), Applicative (Behavior r)) => Context r where
- data Reactive r :: * -> *
- data Event r :: * -> *
- data Behavior r :: * -> *
- sync :: Reactive r a -> IO a
- ioReactive :: IO a -> Reactive r a
- newEvent :: Reactive r (Event r a, a -> Reactive r ())
- listen :: Event r a -> (a -> IO ()) -> Reactive r (IO ())
- never :: Event r a
- merge :: Event r a -> Event r a -> Event r a
- filterJust :: Event r (Maybe a) -> Event r a
- hold :: a -> Event r a -> Reactive r (Behavior r a)
- changes :: Behavior r a -> Event r a
- values :: Behavior r a -> Event r a
- snapshotWith :: (a -> b -> c) -> Event r a -> Behavior r b -> Event r c
- switchE :: Behavior r (Event r a) -> Event r a
- switch :: Behavior r (Behavior r a) -> Reactive r (Behavior r a)
- execute :: Event r (Reactive r a) -> Event r a
- sample :: Behavior r a -> Reactive r a
- coalesce :: (a -> a -> a) -> Event r a -> Event r a
- newBehavior :: forall r a. Context r => a -> Reactive r (Behavior r a, a -> Reactive r ())
- listenValue :: Context r => Behavior r a -> (a -> IO ()) -> Reactive r (IO ())
- mergeWith :: Context r => (a -> a -> a) -> Event r a -> Event r a -> Event r a
- filterE :: Context r => (a -> Bool) -> Event r a -> Event r a
- snapshot :: Context r => Event r a -> Behavior r b -> Event r b
- gate :: Context r => Event r a -> Behavior r Bool -> Event r a
- collectE :: Context r => (a -> s -> (b, s)) -> s -> Event r a -> Reactive r (Event r b)
- collect :: Context r => (a -> s -> (b, s)) -> s -> Behavior r a -> Reactive r (Behavior r b)
- accumE :: Context r => (a -> s -> s) -> s -> Event r a -> Reactive r (Event r s)
- accum :: Context r => (a -> s -> s) -> s -> Event r a -> Reactive r (Behavior r s)
- countE :: Context r => Event r a -> Reactive r (Event r Int)
- count :: Context r => Event r a -> Reactive r (Behavior r Int)
- once :: Context r => Event r a -> Reactive r (Event r a)
Documentation
class (Applicative (Reactive r), Monad (Reactive r), MonadFix (Reactive r), Functor (Event r), Applicative (Behavior r)) => Context r whereSource
data Reactive r :: * -> *Source
A stream of events. The individual firings of events are called 'event occurrences'.
data Behavior r :: * -> *Source
A time-varying value, American spelling.
sync :: Reactive r a -> IO aSource
Execute the specified Reactive
within a new transaction, blocking the caller
until all resulting processing is complete and all callbacks have been called.
This operation is thread-safe, so it may be called from any thread.
State changes to hold
values occur after processing of the transaction is complete.
ioReactive :: IO a -> Reactive r aSource
newEvent :: Reactive r (Event r a, a -> Reactive r ())Source
Returns an event, and a push action for pushing a value into the event.
listen :: Event r a -> (a -> IO ()) -> Reactive r (IO ())Source
Listen for firings of this event. The returned IO ()
is an IO action
that unregisters the listener. This is the observer pattern.
An event that never fires.
merge :: Event r a -> Event r a -> Event r aSource
Merge two streams of events of the same type.
In the case where two event occurrences are simultaneous (i.e. both within the same transaction), both will be delivered in the same transaction.
The order is not defined, because simultaneous events should be considered to be order-agnostic.
filterJust :: Event r (Maybe a) -> Event r aSource
Unwrap Just values, and discard event occurrences with Nothing values.
hold :: a -> Event r a -> Reactive r (Behavior r a)Source
Create a behaviour with the specified initial value, that gets updated by the values coming through the event. The 'current value' of the behaviour is notionally the value as it was 'at the start of the transaction'. That is, state updates caused by event firings get processed at the end of the transaction.
changes :: Behavior r a -> Event r aSource
An event that gives the updates for the behaviour. It doesn't do any equality comparison as the name might imply.
values :: Behavior r a -> Event r aSource
An event that is guaranteed to fires once when you listen to it, giving
the current value of the behaviour, and thereafter behaves like changes
,
firing for each update to the behaviour's value.
snapshotWith :: (a -> b -> c) -> Event r a -> Behavior r b -> Event r cSource
Sample the behaviour at the time of the event firing. Note that the 'current value'
of the behaviour that's sampled is the value as at the start of the transaction
before any state changes of the current transaction are applied through hold
s.
switchE :: Behavior r (Event r a) -> Event r aSource
Unwrap an event inside a behaviour to give a time-varying event implementation.
switch :: Behavior r (Behavior r a) -> Reactive r (Behavior r a)Source
Unwrap a behaviour inside another behaviour to give a time-varying behaviour implementation.
execute :: Event r (Reactive r a) -> Event r aSource
Execute the specified Reactive
action inside an event.
sample :: Behavior r a -> Reactive r aSource
Obtain the current value of a behaviour.
coalesce :: (a -> a -> a) -> Event r a -> Event r aSource
If there's more than one firing in a single transaction, combine them into one using the specified combining function.
mergeWith :: Context r => (a -> a -> a) -> Event r a -> Event r a -> Event r aSource
Merge two streams of events of the same type, combining simultaneous event occurrences.
In the case where multiple event occurrences are simultaneous (i.e. all within the same transaction), they are combined using the supplied function. The output event is guaranteed not to have more than one event occurrence per transaction.
The combine function should be commutative, because simultaneous events should be considered to be order-agnostic.
filterE :: Context r => (a -> Bool) -> Event r a -> Event r aSource
Only keep event occurrences for which the predicate is true.
snapshot :: Context r => Event r a -> Behavior r b -> Event r bSource
Variant of snapshotWith that throws away the event's value and captures the behaviour's.
gate :: Context r => Event r a -> Behavior r Bool -> Event r aSource
Let event occurrences through only when the behaviour's value is True. Note that the behaviour's value is as it was at the start of the transaction, that is, no state changes from the current transaction are taken into account.
collectE :: Context r => (a -> s -> (b, s)) -> s -> Event r a -> Reactive r (Event r b)Source
Transform an event with a generalized state loop (a mealy machine). The function is passed the input and the old state and returns the new state and output value.
collect :: Context r => (a -> s -> (b, s)) -> s -> Behavior r a -> Reactive r (Behavior r b)Source
Transform a behaviour with a generalized state loop (a mealy machine). The function is passed the input and the old state and returns the new state and output value.
accumE :: Context r => (a -> s -> s) -> s -> Event r a -> Reactive r (Event r s)Source
Accumulate on input event, outputting the new state each time.
accum :: Context r => (a -> s -> s) -> s -> Event r a -> Reactive r (Behavior r s)Source
Accumulate on input event, holding state.
countE :: Context r => Event r a -> Reactive r (Event r Int)Source
Count event occurrences, starting with 1 for the first occurrence.