Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
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.
Documentation
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 a
s 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
.
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.
remove :: WeakBagTicket a -> IO () Source #