{- |
A buffer keeping the last value, or zero-order hold.
-}

{-# LANGUAGE RecordWildCards #-}
module FRP.Rhine.ResamplingBuffer.KeepLast where

import FRP.Rhine.ResamplingBuffer
import FRP.Rhine.ResamplingBuffer.Timeless

-- | Always keeps the last input value,
--   or in case of no input an initialisation value.
--   If @cl2@ approximates continuity,
--   this behaves like a zero-order hold.
keepLast :: Monad m => a -> ResamplingBuffer m cl1 cl2 a a
keepLast :: a -> ResamplingBuffer m cl1 cl2 a a
keepLast = AsyncMealy m a a a -> a -> ResamplingBuffer m cl1 cl2 a a
forall (m :: Type -> Type) s a b cl1 cl2.
Monad m =>
AsyncMealy m s a b -> s -> ResamplingBuffer m cl1 cl2 a b
timelessResamplingBuffer AsyncMealy :: forall (m :: Type -> Type) s a b.
(s -> a -> m s) -> (s -> m (b, s)) -> AsyncMealy m s a b
AsyncMealy {a -> m (a, a)
a -> a -> m a
forall (m :: Type -> Type) b. Monad m => b -> m (b, b)
forall (m :: Type -> Type) p a. Monad m => p -> a -> m a
amGet :: a -> m (a, a)
amPut :: a -> a -> m a
amGet :: forall (m :: Type -> Type) b. Monad m => b -> m (b, b)
amPut :: forall (m :: Type -> Type) p a. Monad m => p -> a -> m a
..}
  where
    amPut :: p -> a -> m a
amPut p
_ a
a = a -> m a
forall (m :: Type -> Type) a. Monad m => a -> m a
return a
a
    amGet :: b -> m (b, b)
amGet   b
a = (b, b) -> m (b, b)
forall (m :: Type -> Type) a. Monad m => a -> m a
return (b
a, b
a)