module RingBuffers.Unlifted
( RingBuffer
, new
, clear
, append
, extend
, capacity
, filledLength
, latest
, unsafeLatest
, foldMap
, toList
) where
import qualified RingBuffers.Internal as I
newtype RingBuffer a = RingBuffer (I.RingBuffer UnliftedArray a)
new :: (PrimUnlifted a)
=> Int
-> IO (RingBuffer a)
new :: Int -> IO (RingBuffer a)
new Int
sz = (RingBuffer UnliftedArray a -> RingBuffer a)
-> IO (RingBuffer UnliftedArray a) -> IO (RingBuffer a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RingBuffer UnliftedArray a -> RingBuffer a
coerce (Int -> IO (RingBuffer UnliftedArray a)
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
Int -> IO (RingBuffer arr a)
I.new Int
sz)
clear :: (PrimUnlifted a)
=> RingBuffer a
-> IO ()
clear :: RingBuffer a -> IO ()
clear RingBuffer a
rb = RingBuffer UnliftedArray a -> IO ()
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> IO ()
I.clear (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)
filledLength :: (PrimUnlifted a)
=> RingBuffer a
-> IO Int
filledLength :: RingBuffer a -> IO Int
filledLength RingBuffer a
rb = RingBuffer UnliftedArray a -> IO Int
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> IO Int
I.filledLength (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)
capacity :: (PrimUnlifted a)
=> RingBuffer a
-> IO Int
capacity :: RingBuffer a -> IO Int
capacity RingBuffer a
rb = RingBuffer UnliftedArray a -> IO Int
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> IO Int
I.capacity (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)
latest :: (PrimUnlifted a)
=> RingBuffer a
-> Int
-> IO (Maybe a)
latest :: RingBuffer a -> Int -> IO (Maybe a)
latest RingBuffer a
rb Int
n = RingBuffer UnliftedArray a -> Int -> IO (Maybe a)
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> Int -> IO (Maybe a)
I.latest (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb) Int
n
unsafeLatest :: (PrimUnlifted a)
=> RingBuffer a
-> Int
-> IO a
unsafeLatest :: RingBuffer a -> Int -> IO a
unsafeLatest RingBuffer a
rb Int
n = RingBuffer UnliftedArray a -> Int -> IO a
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> Int -> IO a
I.unsafeLatest (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb) Int
n
append :: (PrimUnlifted a)
=> a
-> RingBuffer a
-> IO ()
append :: a -> RingBuffer a -> IO ()
append a
x RingBuffer a
rb = a -> RingBuffer UnliftedArray a -> IO ()
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
a -> RingBuffer arr a -> IO ()
I.append a
x (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)
extend :: (PrimUnlifted a)
=> UnliftedArray a
-> RingBuffer a
-> IO ()
extend :: UnliftedArray a -> RingBuffer a -> IO ()
extend UnliftedArray a
x RingBuffer a
rb = UnliftedArray a -> RingBuffer UnliftedArray a -> IO ()
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
arr a -> RingBuffer arr a -> IO ()
I.extend UnliftedArray a
x (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)
foldMap :: (PrimUnlifted a, Monoid b)
=> RingBuffer a
-> (a -> IO b)
-> IO b
foldMap :: RingBuffer a -> (a -> IO b) -> IO b
foldMap RingBuffer a
rb a -> IO b
action = RingBuffer UnliftedArray a -> (a -> IO b) -> IO b
forall (arr :: * -> *) a b.
(Contiguous arr, Element arr a, Monoid b) =>
RingBuffer arr a -> (a -> IO b) -> IO b
I.foldMap (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb) a -> IO b
action
toList :: (PrimUnlifted a)
=> RingBuffer a
-> IO [a]
toList :: RingBuffer a -> IO [a]
toList RingBuffer a
rb = RingBuffer UnliftedArray a -> IO [a]
forall (arr :: * -> *) a.
(Contiguous arr, Element arr a) =>
RingBuffer arr a -> IO [a]
I.toList (RingBuffer a -> RingBuffer UnliftedArray a
coerce RingBuffer a
rb)