{-# LANGUAGE RecordWildCards #-}

{- |
A buffer keeping the last value, or zero-order hold.
-}
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 :: forall (m :: Type -> Type) a cl1 cl2.
Monad m =>
a -> ResamplingBuffer m cl1 cl2 a a
keepLast = 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} {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
amPut :: forall {m :: Type -> Type} {p} {a}. Monad m => p -> a -> m a
amGet :: forall {m :: Type -> Type} {b}. Monad m => b -> m (b, b)
..}
  where
    amGet :: b -> m (b, b)
amGet b
a = forall (m :: Type -> Type) a. Monad m => a -> m a
return (b
a, b
a)
    amPut :: p -> a -> m a
amPut p
_ = forall (m :: Type -> Type) a. Monad m => a -> m a
return