Safe Haskell | None |
---|---|
Language | Haskell98 |
FRP.Euphoria.Internal.GenericCollection, with an interface specialised for Enum keys.
- data CollectionUpdate k a
- = AddItem k a
- | RemoveItem k
- data Collection k a
- simpleCollection :: (Enum k, MonadSignalGen m) => k -> Event (a, Event ()) -> m (Collection k a)
- accumCollection :: (Enum k, MonadSignalGen m) => Event (CollectionUpdate k a) -> m (Collection k a)
- collectionToUpdates :: forall m k a. MonadSignalGen m => Collection k a -> m (Event (CollectionUpdate k a))
- emptyCollection :: Collection k a
- collectionFromList :: [(k, a)] -> Collection k a
- collectionFromDiscreteList :: (Enum k, Eq a, MonadSignalGen m) => k -> Discrete [a] -> m (Collection k a)
- makeCollection :: MonadSignalGen m => Discrete [(k, a)] -> Event (CollectionUpdate k a) -> m (Collection k a)
- mapToCollection :: (Eq k, Eq a, Enum k, MonadSignalGen m) => Discrete (EnumMap k a) -> m (Collection k (Discrete a))
- watchCollection :: (Show k, Show a, MonadSignalGen m) => Collection k a -> m (Event (IO ()))
- followCollectionKey :: forall m k a. (Eq k, MonadSignalGen m) => k -> Collection k a -> m (Discrete (Maybe a))
- collectionToDiscreteList :: Collection k a -> Discrete [(k, a)]
- openCollection :: MonadSignalGen m => Collection k a -> m ([(k, a)], Event (CollectionUpdate k a))
- mapCollection :: MonadSignalGen m => (a -> b) -> Collection k a -> m (Collection k b)
- mapCollectionWithKey :: MonadSignalGen m => (k -> a -> b) -> Collection k a -> m (Collection k b)
- filterCollection :: (Enum k, MonadSignalGen m) => (a -> Bool) -> Collection k a -> m (Collection k a)
- filterCollectionWithKey :: (Enum k, MonadSignalGen m) => (k -> a -> Bool) -> Collection k a -> m (Collection k a)
- justCollection :: (Enum k, MonadSignalGen m) => Collection k (Maybe a) -> m (Collection k a)
- mapCollectionM :: (Enum k, MonadSignalGen m) => (a -> SignalGen b) -> Collection k a -> m (Collection k b)
- sequenceCollection :: (Enum k, MonadSignalGen m) => Collection k (SignalGen a) -> m (Collection k a)
Documentation
data CollectionUpdate k a Source #
Represents an incremental change to a collection of items.
AddItem k a | |
RemoveItem k |
Functor (CollectionUpdate k) Source # | |
Foldable (CollectionUpdate k) Source # | |
Traversable (CollectionUpdate k) Source # | |
(Eq k, Eq a) => Eq (CollectionUpdate k a) Source # | |
(Show k, Show a) => Show (CollectionUpdate k a) Source # | |
Generic (CollectionUpdate k a) Source # | |
(NFData k, NFData v) => NFData (CollectionUpdate k v) Source # | |
type Rep (CollectionUpdate k a) Source # | |
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].
SignalSet (Collection k a) Source # | |
creating collections
simpleCollection :: (Enum k, MonadSignalGen m) => k -> Event (a, Event ()) -> m (Collection k a) Source #
accumCollection :: (Enum k, MonadSignalGen m) => Event (CollectionUpdate k a) -> m (Collection k a) Source #
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 #
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.
mapToCollection :: (Eq k, Eq a, Enum k, MonadSignalGen m) => Discrete (EnumMap k a) -> m (Collection k (Discrete a)) Source #
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 #
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 :: (Enum k, MonadSignalGen m) => (k -> a -> Bool) -> Collection k a -> m (Collection k a) Source #
justCollection :: (Enum k, MonadSignalGen m) => Collection k (Maybe a) -> m (Collection k a) Source #
mapCollectionM :: (Enum k, MonadSignalGen m) => (a -> SignalGen b) -> Collection k a -> m (Collection k b) Source #
sequenceCollection :: (Enum k, MonadSignalGen m) => Collection k (SignalGen a) -> m (Collection k a) Source #