Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data RingBuffer a
- new :: Int -> IO (RingBuffer a)
- clear :: RingBuffer a -> IO ()
- append :: a -> RingBuffer a -> IO ()
- extend :: Array a -> RingBuffer a -> IO ()
- capacity :: RingBuffer a -> IO Int
- filledLength :: RingBuffer a -> IO Int
- latest :: RingBuffer a -> Int -> IO (Maybe a)
- unsafeLatest :: RingBuffer a -> Int -> IO a
- foldMap :: Monoid b => RingBuffer a -> (a -> IO b) -> IO b
- toList :: RingBuffer a -> IO [a]
Documentation
data RingBuffer a Source #
A concurrent, mutable ring buffer that supports atomic updates.
:: Int | capacity of buffer |
-> IO (RingBuffer a) |
Return a new ring buffer of the specified size.
append :: a -> RingBuffer a -> IO () Source #
Add an item to the end of the buffer.
extend :: Array a -> RingBuffer a -> IO () Source #
Write multiple items to the end of the ring.
Ignores any elements of the input array whose indices are higher than the length of the ring buffer.
filledLength :: RingBuffer a -> IO Int Source #
Get the current filled length of the ring
latest :: RingBuffer a -> Int -> IO (Maybe a) Source #
Retrieve the \(n\)th most-recently added item of the ring
unsafeLatest :: RingBuffer a -> Int -> IO a Source #
Retrieve the \(n\)th most-recently added item of the ring
Note: This function may exhibit undefined behaviour if the index is out-of-bounds or uninitialised.
foldMap :: Monoid b => RingBuffer a -> (a -> IO b) -> IO b Source #
Execute the given action with the items of the ring, accumulating its results.
toList :: RingBuffer a -> IO [a] Source #
Convert the entire contents of the ring into a list, with the most recently added element at the head.