{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_HADDOCK hide #-}
module Streaming.Linear.Internal.Interop
(
reread,
)
where
import qualified Control.Functor.Linear as Control
import Data.Unrestricted.Linear
import Prelude.Linear (($))
import Streaming.Linear.Internal.Produce
import Streaming.Linear.Internal.Type
import Prelude (Maybe (..))
reread ::
(Control.Monad m) =>
(s -> m (Ur (Maybe a))) ->
s ->
Stream (Of a) m ()
reread :: forall (m :: * -> *) s a.
Monad m =>
(s -> m (Ur (Maybe a))) -> s -> Stream (Of a) m ()
reread s -> m (Ur (Maybe a))
f s
s = forall (m :: * -> *) s a.
Monad m =>
(s -> m (Ur (Maybe a))) -> s -> Stream (Of a) m ()
reread' s -> m (Ur (Maybe a))
f s
s
where
reread' ::
(Control.Monad m) =>
(s -> m (Ur (Maybe a))) ->
s ->
Stream (Of a) m ()
reread' :: forall (m :: * -> *) s a.
Monad m =>
(s -> m (Ur (Maybe a))) -> s -> Stream (Of a) m ()
reread' s -> m (Ur (Maybe a))
f s
s = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Control.do
Ur Maybe a
maybeA <- s -> m (Ur (Maybe a))
f s
s
case Maybe a
maybeA of
Maybe a
Nothing -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
Just a
a -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ (forall (m :: * -> *) a. Monad m => a -> Stream (Of a) m ()
yield a
a forall (m :: * -> *) a. Monad m => m () %1 -> m a %1 -> m a
Control.>> forall (m :: * -> *) s a.
Monad m =>
(s -> m (Ur (Maybe a))) -> s -> Stream (Of a) m ()
reread s -> m (Ur (Maybe a))
f s
s)
{-# INLINEABLE reread #-}