{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RecordWildCards #-}
module FRP.Rhine.ResamplingBuffer.Collect where
import Data.Sequence
import FRP.Rhine.ResamplingBuffer
import FRP.Rhine.ResamplingBuffer.Timeless
collect :: Monad m => ResamplingBuffer m cl1 cl2 a [a]
collect :: ResamplingBuffer m cl1 cl2 a [a]
collect = 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) a. Monad m => [a] -> a -> m [a]
forall (m :: Type -> Type) a a. Monad m => a -> m (a, [a])
amGet :: [a] -> m ([a], [a])
amPut :: [a] -> a -> m [a]
amGet :: forall (m :: Type -> Type) a a. Monad m => a -> m (a, [a])
amPut :: forall (m :: Type -> Type) a. Monad m => [a] -> a -> m [a]
..} []
where
amPut :: [a] -> a -> m [a]
amPut [a]
as a
a = [a] -> m [a]
forall (m :: Type -> Type) a. Monad m => a -> m a
return ([a] -> m [a]) -> [a] -> m [a]
forall a b. (a -> b) -> a -> b
$ a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as
amGet :: a -> m (a, [a])
amGet a
as = (a, [a]) -> m (a, [a])
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
as, [])
collectSequence :: Monad m => ResamplingBuffer m cl1 cl2 a (Seq a)
collectSequence :: ResamplingBuffer m cl1 cl2 a (Seq a)
collectSequence = AsyncMealy m (Seq a) a (Seq a)
-> Seq a -> ResamplingBuffer m cl1 cl2 a (Seq 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 {Seq a -> m (Seq a, Seq a)
Seq a -> a -> m (Seq a)
forall (m :: Type -> Type) a. Monad m => Seq a -> a -> m (Seq a)
forall (m :: Type -> Type) a a. Monad m => a -> m (a, Seq a)
amGet :: forall (m :: Type -> Type) a a. Monad m => a -> m (a, Seq a)
amPut :: forall (m :: Type -> Type) a. Monad m => Seq a -> a -> m (Seq a)
amGet :: Seq a -> m (Seq a, Seq a)
amPut :: Seq a -> a -> m (Seq a)
..} Seq a
forall a. Seq a
empty
where
amPut :: Seq a -> a -> m (Seq a)
amPut Seq a
as a
a = Seq a -> m (Seq a)
forall (m :: Type -> Type) a. Monad m => a -> m a
return (Seq a -> m (Seq a)) -> Seq a -> m (Seq a)
forall a b. (a -> b) -> a -> b
$ a
a a -> Seq a -> Seq a
forall a. a -> Seq a -> Seq a
<| Seq a
as
amGet :: a -> m (a, Seq a)
amGet a
as = (a, Seq a) -> m (a, Seq a)
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
as, Seq a
forall a. Seq a
empty)
pureBuffer :: Monad m => ([a] -> b) -> ResamplingBuffer m cl1 cl2 a b
pureBuffer :: ([a] -> b) -> ResamplingBuffer m cl1 cl2 a b
pureBuffer [a] -> b
f = AsyncMealy m [a] a b -> [a] -> ResamplingBuffer m cl1 cl2 a b
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 (b, [a])
[a] -> a -> m [a]
forall (m :: Type -> Type) a. Monad m => [a] -> m (b, [a])
forall (m :: Type -> Type) a. Monad m => [a] -> a -> m [a]
amGet :: forall (m :: Type -> Type) a. Monad m => [a] -> m (b, [a])
amPut :: forall (m :: Type -> Type) a. Monad m => [a] -> a -> m [a]
amGet :: [a] -> m (b, [a])
amPut :: [a] -> a -> m [a]
..} []
where
amPut :: [a] -> a -> m [a]
amPut [a]
as a
a = [a] -> m [a]
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as)
amGet :: [a] -> m (b, [a])
amGet [a]
as = (b, [a]) -> m (b, [a])
forall (m :: Type -> Type) a. Monad m => a -> m a
return ([a] -> b
f [a]
as, [])
foldBuffer
:: Monad m
=> (a -> b -> b)
-> b
-> ResamplingBuffer m cl1 cl2 a b
foldBuffer :: (a -> b -> b) -> b -> ResamplingBuffer m cl1 cl2 a b
foldBuffer a -> b -> b
f = AsyncMealy m b a b -> b -> ResamplingBuffer m cl1 cl2 a b
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 {b -> m (b, b)
b -> a -> m b
forall (m :: Type -> Type). Monad m => b -> a -> m b
forall (m :: Type -> Type) b. Monad m => b -> m (b, b)
amGet :: forall (m :: Type -> Type) b. Monad m => b -> m (b, b)
amPut :: forall (m :: Type -> Type). Monad m => b -> a -> m b
amGet :: b -> m (b, b)
amPut :: b -> a -> m b
..}
where
amPut :: b -> a -> m b
amPut b
b a
a = let !b' :: b
b' = a -> b -> b
f a
a b
b in b -> m b
forall (m :: Type -> Type) a. Monad m => a -> m a
return b
b'
amGet :: b -> m (b, b)
amGet b
b = (b, b) -> m (b, b)
forall (m :: Type -> Type) a. Monad m => a -> m a
return (b
b, b
b)