euphoria-0.6.0.1: Dynamic network FRP with events and continuous values

Safe HaskellNone
LanguageHaskell98

FRP.Euphoria.Collection

Contents

Description

Collection signals with incremental updates.

Synopsis

Documentation

data CollectionUpdate k a Source

Represents an incremental change to a collection of items.

Constructors

AddItem k a 
RemoveItem k 

data Collection k a Source

An FRP interface for representing an incrementally updated collection of items. The items are identified by a unique key. Items may be added or removed from the current collection.

This type is useful because it allows you to manage the incremental state updates to something that needs a collection of items without having to rebuild it completely every time the collection changes. Consider the type Signal [a] -- functionally, it also represents a collection of items that changes over time. However, there is no state carried between changes. If, for example, we have a GUI widget that lists items whose content is represented as a Signal [a], we would have to destroy and rebuild the widget's internal state every time the list contents change. But with the Collection type, we can add or remove from the GUI widget only the necessary items. This is useful both from a performance (most existing GUI toolkits exhibit worse performance when adding and removing all items with every change) and behavior standpoint, because the GUI toolkit can, for example, remember which items the user had selected between list updates.

Usage of Collection implies there could be some caching/state by the consumer of the Events, otherwise one might as well use a Signal [a].

Instances

creating collections

simpleCollection Source

Arguments

:: (Enum k, MonadSignalGen m) 
=> k

The initial value for the unique keys. succ will be used to get further keys.

-> Event (a, Event ())

An Event that introduces a new item and its subsequent removal Event. The item will be removed from the collection when the Event () fires.

-> m (Collection k a) 

A collection whose items are created by an event, and removed by another event.

collectionToUpdates :: forall m k a. MonadSignalGen m => Collection k a -> m (Event (CollectionUpdate k a)) Source

Create an Event stream of all updates from a collection, including the items currently in it.

emptyCollection :: Collection k a Source

An empty, unchanging Collection.

collectionFromList :: [(k, a)] -> Collection k a Source

A pure function to create a Collection from key-value pairs. This collection will never change.

collectionFromDiscreteList :: (Enum k, Eq a, MonadSignalGen m) => k -> Discrete [a] -> m (Collection k a) Source

A somewhat inefficient but easy-to-use way of turning a list of items into a Collection. Probably should only be used for temporary hacks. Will perform badly with large lists.

makeCollection :: MonadSignalGen m => Discrete [(k, a)] -> Event (CollectionUpdate k a) -> m (Collection k a) Source

The primitive interface for creating a Collection. The two arguments must be coherent, i.e. the value of the discrete at time t+1 should be obtained by applying the updates at t+1 to the value of the discrete at t. This invariant is not checked.

observing collections

watchCollection :: (Show k, Show a, MonadSignalGen m) => Collection k a -> m (Event (IO ())) Source

Prints add/remove diagnostics for a Collection. Useful for debugging

followCollectionKey :: forall m k a. (Eq k, MonadSignalGen m) => k -> Collection k a -> m (Discrete (Maybe a)) Source

Look for a key in a collection, and give its (potentially nonexistant) value over time.

collectionToDiscreteList :: Collection k a -> Discrete [(k, a)] Source

Extracts a Discrete which represents the current state of a collection.

openCollection :: MonadSignalGen m => Collection k a -> m ([(k, a)], Event (CollectionUpdate k a)) Source

Extracts a snapshot of the current values in a collection with an Event stream of further updates

other functions

mapCollection :: MonadSignalGen m => (a -> b) -> Collection k a -> m (Collection k b) Source

Like fmap, but the Collection and interior Event stream are memoized

mapCollectionWithKey :: MonadSignalGen m => (k -> a -> b) -> Collection k a -> m (Collection k b) Source

A version of mapCollection which provides access to the key

filterCollection :: (Enum k, MonadSignalGen m) => (a -> Bool) -> Collection k a -> m (Collection k a) Source

filterCollectionWithKey :: forall m k a. (Enum k, MonadSignalGen m) => (k -> a -> Bool) -> Collection k a -> m (Collection k a) Source

justCollection :: forall m k a. (Enum k, MonadSignalGen m) => Collection k (Maybe a) -> m (Collection k a) Source