Copyright | (c) Atze van der Ploeg 2015 |
---|---|

License | BSD-style |

Maintainer | atzeus@gmail.org |

Stability | provisional |

Portability | portable |

Safe Haskell | None |

Language | Haskell98 |

Event streams for FRPNow

- data EvStream a
- next :: EvStream a -> Behavior (Event a)
- nextAll :: EvStream a -> Behavior (Event [a])
- emptyEs :: EvStream a
- merge :: EvStream a -> EvStream a -> EvStream a
- toChanges :: Eq a => Behavior a -> EvStream a
- edges :: Behavior Bool -> EvStream ()
- scanlEv :: (a -> b -> a) -> a -> EvStream b -> Behavior (EvStream a)
- foldrEv :: (a -> Event b -> b) -> EvStream a -> Behavior (Event b)
- foldriEv :: a -> (a -> Event b -> b) -> EvStream a -> Behavior b
- fromChanges :: a -> EvStream a -> Behavior (Behavior a)
- foldrSwitch :: Behavior a -> EvStream (Behavior a) -> Behavior (Behavior a)
- foldEs :: (a -> b -> a) -> a -> EvStream b -> Behavior (Behavior a)
- foldBs :: Behavior a -> (Behavior a -> b -> Behavior a) -> EvStream b -> Behavior (Behavior a)
- catMaybesEs :: EvStream (Maybe a) -> EvStream a
- filterEs :: (a -> Bool) -> EvStream a -> EvStream a
- filterMapEs :: (a -> Maybe b) -> EvStream a -> EvStream b
- filterMapEsB :: Behavior (a -> Maybe b) -> EvStream a -> EvStream b
- filterB :: Behavior (a -> Bool) -> EvStream a -> EvStream a
- during :: EvStream a -> Behavior Bool -> EvStream a
- beforeEs :: EvStream a -> Event () -> EvStream a
- (<@@>) :: Behavior (a -> b) -> EvStream a -> EvStream b
- snapshots :: Behavior a -> EvStream () -> EvStream a
- callbackStream :: Now (EvStream a, a -> IO ())
- callStream :: ([a] -> Now ()) -> EvStream a -> Now ()
- callIOStream :: (a -> IO ()) -> EvStream a -> Now ()
- traceEs :: (Show a, Eq a) => String -> EvStream a -> Now ()

# Documentation

The (abstract) type of event streams.

Denotationally, one can think of an eventstream a value of type

[(Time,a)]

Where the points in time are non-strictly increasing. There can be multiple simulatinous events in an event stream.

# Observe

next :: EvStream a -> Behavior (Event a) Source

Obtain the next element of the event stream. The obtained event is guaranteed to lie in the future.

nextAll :: EvStream a -> Behavior (Event [a]) Source

Obtain all simultaneous next elements of the event stream. The obtained event is guaranteed to lie in the future.

# Construction

merge :: EvStream a -> EvStream a -> EvStream a Source

Merge two event stream.

In case of simultaneity, the left elements come first

toChanges :: Eq a => Behavior a -> EvStream a Source

Get the event stream of changes to the input behavior.

edges :: Behavior Bool -> EvStream () Source

Get the events that the behavior changes from `False`

to `True`

# Folds and scans

scanlEv :: (a -> b -> a) -> a -> EvStream b -> Behavior (EvStream a) Source

A left scan over an event stream

foldrEv :: (a -> Event b -> b) -> EvStream a -> Behavior (Event b) Source

Right fold over an eventstream

The result of folding over the rest of the event stream is in an event, since it can be only known in the future.

No initial value needs to be given, since the initial value is `never`

foldriEv :: a -> (a -> Event b -> b) -> EvStream a -> Behavior b Source

Right fold over an eventstream with a left initial value

Defined as:

foldriEv i f ev = f i <$> foldrEv f es

fromChanges :: a -> EvStream a -> Behavior (Behavior a) Source

Create a behavior from an initial value and a event stream of updates.

foldrSwitch :: Behavior a -> EvStream (Behavior a) -> Behavior (Behavior a) Source

Start with the argument behavior, and switch to a new behavior each time an event in the event stream occurs.

Defined as:

foldrSwitch b = foldriEv b switch

foldEs :: (a -> b -> a) -> a -> EvStream b -> Behavior (Behavior a) Source

Left fold over an eventstream to create a behavior (behavior depends on when the fold started).

foldBs :: Behavior a -> (Behavior a -> b -> Behavior a) -> EvStream b -> Behavior (Behavior a) Source

Yet another type of fold.

Defined as:

foldBs b f es = scanlEv f b es >>= foldrSwitch b

# Filter and scan

filterMapEs :: (a -> Maybe b) -> EvStream a -> EvStream b Source

Shorthand for

filterMapEs f e = catMaybesEs $ f <$> e

filterMapEsB :: Behavior (a -> Maybe b) -> EvStream a -> EvStream b Source

Shorthand for

filterMapEs b e = catMaybesEs $ b <@@> e

filterB :: Behavior (a -> Bool) -> EvStream a -> EvStream a Source

Filter events from an eventstream based on a function that changes over time

during :: EvStream a -> Behavior Bool -> EvStream a Source

Obtain only the events from input stream that occur while
the input behavior is `True`

beforeEs :: EvStream a -> Event () -> EvStream a Source

An event stream with only elements that occur before the argument event.

# Combine behavior and eventstream

(<@@>) :: Behavior (a -> b) -> EvStream a -> EvStream b Source

Sample the behavior each time an event in the stream occurs, and combine the outcomes.

snapshots :: Behavior a -> EvStream () -> EvStream a Source

Sample the behavior each time an event in the stream occurs.

# IO interface

callbackStream :: Now (EvStream a, a -> IO ()) Source

Create an event stream that has an event each time the returned function is called. The function can be called from any thread.

callStream :: ([a] -> Now ()) -> EvStream a -> Now () Source

Call the given function each time an event occurs, and execute the resulting Now computation

callIOStream :: (a -> IO ()) -> EvStream a -> Now () Source

Execute the given IO action each time an event occurs. The IO action is executed on the main thread, so it should not take a long time.