Safe Haskell | None |
---|
- data Event a
- data Reactive a
- stepper :: a -> Event a -> Reactive a
- maybeStepper :: Event a -> Reactive (Maybe a)
- sampleAndHold2 :: b -> Reactive b -> Event a -> Reactive b
- apply :: Reactive (a -> b) -> Event a -> Event b
- filter' :: Reactive (a -> Bool) -> Event a -> Event a
- gate :: Reactive Bool -> Event a -> Event a
- sample :: Reactive b -> Event a -> Event b
- snapshot :: Reactive a -> Event b -> Event (a, b)
- snapshotWith :: (a -> b -> c) -> Reactive a -> Event b -> Event c
- justE :: Event (Maybe a) -> Event a
- splitE :: Event (Either a b) -> (Event a, Event b)
- eitherE :: Event a -> Event b -> Event (Either a b)
- lastE :: Event a -> Event a
- delayE :: Int -> Event a -> Event a
- recallEWith :: (b -> b -> a) -> Event b -> Event a
- diffE :: Num a => Event a -> Event a
- bufferE :: Int -> Event a -> Event [a]
- gatherE :: Int -> Event a -> Event [a]
- scatterE :: Event [a] -> Event a
- accumE :: a -> Event (a -> a) -> Event a
- accumR :: a -> Event (a -> a) -> Reactive a
- foldpE :: (a -> b -> b) -> b -> Event a -> Event b
- foldpR :: (a -> b -> b) -> b -> Event a -> Reactive b
- scanlE :: (a -> b -> a) -> a -> Event b -> Event a
- scanlR :: (a -> b -> a) -> a -> Event b -> Reactive a
- mapAccum :: a -> Event (a -> (b, a)) -> (Event b, Reactive a)
- firstE :: Event a -> Event a
- restE :: Event a -> Event a
- countE :: Enum b => Event a -> Event b
- countR :: Enum b => Event a -> Reactive b
- monoidE :: Monoid a => Event a -> Event a
- monoidR :: Monoid a => Event a -> Reactive a
- sumE :: Num a => Event a -> Event a
- productE :: Num a => Event a -> Event a
- allE :: Event Bool -> Event Bool
- anyE :: Event Bool -> Event Bool
- sumR :: Num a => Event a -> Reactive a
- productR :: Num a => Event a -> Reactive a
- allR :: Event Bool -> Reactive Bool
- anyR :: Event Bool -> Reactive Bool
- tickE :: Event a -> Event ()
- onR :: Event a -> Reactive Bool
- offR :: Event a -> Reactive Bool
- toggleR :: Event a -> Reactive Bool
- pulse :: DiffTime -> Event ()
- time :: Fractional a => Reactive a
- integral :: Fractional b => Event a -> Reactive b -> Reactive b
- data TransportControl t
- transport :: (Ord t, Fractional t) => Event (TransportControl t) -> Event a -> Reactive t -> Reactive t
- record :: Ord t => Reactive t -> Event a -> Reactive [(t, a)]
- playback :: Ord t => Reactive t -> Reactive [(t, a)] -> Event a
- playback' :: Ord t => Event b -> Reactive t -> Reactive [(t, a)] -> Event [(t, a)]
- seqE :: Event a -> Event b -> Event b
- oftenE :: Event ()
- getCharE :: Event Char
- putCharE :: Event Char -> Event Char
- getLineE :: Event String
- putLineE :: Event String -> Event String
- systemTimeR :: Reactive UTCTime
- systemTimeSecondsR :: Reactive DiffTime
- systemTimeDayR :: Reactive Day
- readChanE :: Chan a -> Event a
- writeChanE :: Chan a -> Event a -> Event a
- getE :: IO a -> Event a
- pollE :: IO (Maybe a) -> Event a
- putE :: (a -> IO ()) -> Event a -> Event a
- run :: Event a -> IO ()
- runLoop :: Event a -> IO ()
- runLoopUntil :: Event (Maybe a) -> IO a
- type Source a = Event a
- type Sink a = Event a -> Event ()
- newSource :: IO (a -> IO (), Source a)
- newSink :: IO (IO (Maybe a), Sink a)
- notify :: String -> Event a -> Event a
- showing :: Show a => String -> Event a -> Event a
- runEvent :: Show a => Event a -> IO ()
- runReactive :: Show a => Reactive a -> IO ()
- unsafeGetReactive :: Reactive a -> a
Types
A stream of values.
type Event a = [(Time, a)]
A time-varying value.
type Reactive a = Time -> a
Functor Reactive | Reactive is a functor: |
Applicative Reactive | Reactive is an applicative functor: |
Enum a => Enum (Reactive a) | |
Eq (Reactive b) | |
Floating b => Floating (Reactive b) | |
Fractional b => Fractional (Reactive b) | |
Integral a => Integral (Reactive a) | |
Num a => Num (Reactive a) | |
Ord b => Ord (Reactive b) | |
(Num a, Ord a) => Real (Reactive a) | |
IsString a => IsString (Reactive a) | |
Monoid a => Monoid (Reactive a) | Reactive has a lifted is a monoid: |
VectorSpace v => VectorSpace (Reactive v) | |
AdditiveGroup v => AdditiveGroup (Reactive v) |
Basic combinators
Event to reactive
maybeStepper :: Event a -> Reactive (Maybe a)Source
sampleAndHold2 :: b -> Reactive b -> Event a -> Reactive bSource
Reactive to event
apply :: Reactive (a -> b) -> Event a -> Event bSource
Apply the values of an event to a time-varying function.
r `apply` e = r `snapshotWith ($)` e
filter' :: Reactive (a -> Bool) -> Event a -> Event aSource
Filter an event based on a time-varying predicate.
r `filter'` e = justE $ (partial <$> r) `apply` e
gate :: Reactive Bool -> Event a -> Event aSource
Filter an event based on a time-varying toggle.
r `gate` e = (const <$> r) `filter'` e
sample :: Reactive b -> Event a -> Event bSource
Sample a time-varying value.
r `snapshot` e = snapshotWith const
snapshot :: Reactive a -> Event b -> Event (a, b)Source
Sample a time-varying value with the value of the trigger.
r `snapshot` e = snapshotWith (,)
snapshotWith :: (a -> b -> c) -> Reactive a -> Event b -> Event cSource
Sample a time-varying value with the value of the trigger, using the given function to combine.
r `snapshotWith f` e = (f <$> r) `apply` e
Merging and splitting values
splitE :: Event (Either a b) -> (Event a, Event b)Source
Partition values of different types. See also partitionE
.
let (x, y) in eitherE x y = splitE e ≡ e
Past-dependent values
Buffering events
recallEWith :: (b -> b -> a) -> Event b -> Event aSource
Pack with last value. Similar to withPrevEWith
in reactive but flipped.
bufferE :: Int -> Event a -> Event [a]Source
Buffer up to n values. When the buffer is full, old elements will be rotated out.
bufferE n e = [[e1],[e1,e2]..[e1..en],[e2..en+1]..]
gatherE :: Int -> Event a -> Event [a]Source
Gather event values into chunks of regular size.
gatherE n e = [[e1..en],[en+1..e2n]..]
scatterE :: Event [a] -> Event aSource
Separate chunks of values.
scatterE [e1,e2..] = [e1] <> [e2] ..
Accumulating values
accumE :: a -> Event (a -> a) -> Event aSource
Event accumulator.
a `accumE` e = (a `accumR` e) `sample` e a `accumR` e = a `stepper` (a `accumE` e)
accumR :: a -> Event (a -> a) -> Reactive aSource
Reactive accumulator.
a `accumE` e = (a `accumR` e) `sample` e a `accumR` e = a `stepper` (a `accumE` e)
foldpE :: (a -> b -> b) -> b -> Event a -> Event bSource
Create a past-dependent event.
scanlE f z x = foldpE (flip f) f z x
foldpR :: (a -> b -> b) -> b -> Event a -> Reactive bSource
Create a past-dependent reactive. This combinator corresponds to scanl
on streams.
scanlR f z x = foldpR (flip f) f z x
scanlE :: (a -> b -> a) -> a -> Event b -> Event aSource
Create a past-dependent event. This combinator corresponds to scanl
on streams.
scanlE f z x = foldpE (flip f) f z x
scanlR :: (a -> b -> a) -> a -> Event b -> Reactive aSource
Create a past-dependent reactive. This combinator corresponds to scanl
on streams.
scanlR f z x = foldpR (flip f) f z x
Special accumulators
monoidE :: Monoid a => Event a -> Event aSource
Create a past-dependent event using a Monoid
instance.
monoidR :: Monoid a => Event a -> Reactive aSource
Create a past-dependent event using a Monoid
instance.
Lifted monoids
Toggles and switches
tickE :: Event a -> Event ()Source
Throw away values of the event.
This is of course just () <$ x
but it is useful to fix the type in some cases.
Time
time :: Fractional a => Reactive aSource
A generalized time behaviour.
integral :: Fractional b => Event a -> Reactive b -> Reactive bSource
Integrates a behaviour.
integral pulse behavior
Record and playback
data TransportControl t Source
Play | Play from the current position. |
Reverse | Play in reverse from the current position. |
Pause | Stop playing, and retain current position. |
Stop | Stop and reset position. |
Eq (TransportControl t) | |
Ord (TransportControl t) | |
Show (TransportControl t) |
transport :: (Ord t, Fractional t) => Event (TransportControl t) -> Event a -> Reactive t -> Reactive tSource
Generates a cursor that moves forward or backward continuously.
The cursor may be started, stopped, moved by sending a TransportControl
event.
transport control pulse speed
playback :: Ord t => Reactive t -> Reactive [(t, a)] -> Event aSource
Play back a list of values.
This function will sample the time behaviour at an arbitrary
small interval. To get precise control of how time is sampled,
use playback'
instead.
playback' :: Ord t => Event b -> Reactive t -> Reactive [(t, a)] -> Event [(t, a)]Source
Play back a list of values.
Special functions
Creating events and reactives
From standard library
From channels
writeChanE :: Chan a -> Event a -> Event aSource
Event writing to a channel.
From IO
Event reading from external world. The computation should be blocking and is polled exactly once per value.
This function can be used with standard I/O functions.
pollE :: IO (Maybe a) -> Event aSource
Event reading from external world. The computation should be non-blocking and may be polled repeatedly for each value.
This function should be used with non-effectful functions, typically functions that observe the current value of some external property. You should not use this function with standard I/O functions as this may lead to non-deterministic reads (i.e. loss of data).
putE :: (a -> IO ()) -> Event a -> Event aSource
Event writing to the external world.
This function can be used with standard I/O functions.
Run events
runLoopUntil :: Event (Maybe a) -> IO aSource
Run the given event until the first Just x
value, then return x
.
Utility
notify :: String -> Event a -> Event aSource
Behaves like the original event but writes a given message to the standard output for each value.
showing :: Show a => String -> Event a -> Event aSource
Behaves like the original event but writes its value, prepended by the given message, for each value.
runReactive :: Show a => Reactive a -> IO ()Source
unsafeGetReactive :: Reactive a -> aSource