module Control.Wire.Prefab.Queue
(
fifo,
lifo
)
where
import qualified Data.Sequence as S
import Control.Wire.Types
import Data.Monoid
import Data.Sequence (Seq, ViewL(..), (><))
fifo :: forall a e (>~). Monoid e => Wire e (>~) [a] a
fifo = fifo' S.empty
where
fifo' :: Seq a -> Wire e (>~) [a] a
fifo' xs' =
mkPure $ \((xs' ><) . S.fromList -> xs) ->
case S.viewl xs of
x :< rest -> (Right x, fifo' rest)
EmptyL -> (Left mempty, fifo' xs)
lifo :: forall a e (>~). Monoid e => Wire e (>~) [a] a
lifo = lifo' S.empty
where
lifo' :: Seq a -> Wire e (>~) [a] a
lifo' xs' =
mkPure $ \((>< xs') . S.fromList -> xs) ->
case S.viewl xs of
x :< rest -> (Right x, lifo' rest)
EmptyL -> (Left mempty, lifo' xs)