weak-bag-0.1.0.0: Mutable bag backed by weak pointers to each item

Safe HaskellSafe
LanguageHaskell2010

Data.WeakBag

Description

This module defines the WeakBag type, which represents a mutable collection of items that does not cause the items to be retained in memory. It is useful for situations where a value needs to be inspected or modified if it is still alive, but can be ignored if it is dead.

Synopsis

Documentation

data WeakBag a Source #

A WeakBag a holds a set of values of type a, but does not retain them - that is, they can still be garbage-collected. As long as the as remain alive, the WeakBag will continue to refer to them.

data WeakBagTicket a Source #

When inserting an item into a WeakBag, a WeakBagTicket is returned. If the caller retains the ticket, the item is guaranteed to stay in memory (and thus in the WeakBag). The ticket can also be used to remove the item from the WeakBag prematurely (i.e. while it is still alive), using remove.

insert :: a -> WeakBag a -> IO (WeakBagTicket a) Source #

Insert an item into a WeakBag.

empty :: IO (WeakBag a) Source #

Create an empty WeakBag.

isEmpty :: WeakBag a -> IO Bool Source #

Check whether a WeakBag is empty.

traverse :: forall a m. MonadIO m => WeakBag a -> (a -> m ()) -> m () Source #

Visit every node in the given list. If new nodes are appended during the traversal, they will not be visited. Every live node that was in the list when the traversal began will be visited exactly once; however, no guarantee is made about the order of the traversal.