{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Streaming.Linear
(
module Streaming.Internal.Type
, yields
, effect
, wrap
, replicates
, replicatesM
, unfold
, untilJust
, streamBuild
, delays
, maps
, mapsPost
, mapsM
, mapsMPost
, mapped
, mappedPost
, hoistUnexposed
, groups
, inspect
, splitsAt
, chunksOf
, concats
, intercalates
, unzips
, separate
, unseparate
, decompose
, expand
, expandPost
, mapsM_
, run
, streamFold
, iterTM
, iterT
, destroy
) where
import Streaming.Internal.Type
import Streaming.Internal.Process (destroyExposed)
import Data.Functor.Sum
import Data.Functor.Compose
import qualified Streaming.Prelude.Linear as Stream
import System.IO.Linear
import Prelude.Linear (($), (.), (&))
import Prelude (Ordering(..), Ord(..), Num(..), Int, Either(..), Double,
Maybe(..), fromInteger)
import qualified Prelude
import qualified Control.Functor.Linear as Control
import qualified Data.Functor.Linear as Data
import Data.Unrestricted.Linear
import Control.Concurrent (threadDelay)
import GHC.Stack
yields :: (Control.Monad m, Control.Functor f) => f r %1-> Stream f m r
yields :: forall (m :: * -> *) (f :: * -> *) r.
(Monad m, Functor f) =>
f r %1 -> Stream f m r
yields f r
fr = f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m r) %1 -> Stream f m r)
%1 -> f (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (r %1 -> Stream f m r) %1 -> f r %1 -> f (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return f r
fr
{-# INLINE yields #-}
effect :: (Control.Monad m, Control.Functor f) =>
m (Stream f m r) %1-> Stream f m r
effect :: forall (m :: * -> *) (f :: * -> *) r.
(Monad m, Functor f) =>
m (Stream f m r) %1 -> Stream f m r
effect = m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect
{-# INLINE effect #-}
wrap :: (Control.Monad m, Control.Functor f) =>
f (Stream f m r) %1-> Stream f m r
wrap :: forall (m :: * -> *) (f :: * -> *) r.
(Monad m, Functor f) =>
f (Stream f m r) %1 -> Stream f m r
wrap = f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step
{-# INLINE wrap #-}
replicates :: (HasCallStack, Control.Monad m, Control.Functor f) =>
Int -> f () -> Stream f m ()
replicates :: forall (m :: * -> *) (f :: * -> *).
(HasCallStack, Monad m, Functor f) =>
Int -> f () -> Stream f m ()
replicates Int
n f ()
f = Int -> f () -> Stream f m ()
forall (m :: * -> *) (f :: * -> *).
(HasCallStack, Monad m, Functor f) =>
Int -> f () -> Stream f m ()
replicates' Int
n f ()
f
where
replicates' :: (HasCallStack, Control.Monad m, Control.Functor f) =>
Int -> f () -> Stream f m ()
replicates' :: forall (m :: * -> *) (f :: * -> *).
(HasCallStack, Monad m, Functor f) =>
Int -> f () -> Stream f m ()
replicates' Int
n f ()
f = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
n Int
0 of
Ordering
LT -> [Char] -> Stream f m ()
forall a. HasCallStack => [Char] -> a
Prelude.error [Char]
"replicates called with negative integer"
Ordering
EQ -> () -> Stream f m ()
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
Ordering
GT -> f (Stream f m ()) %1 -> Stream f m ()
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m ()) %1 -> Stream f m ())
%1 -> f (Stream f m ()) %1 -> Stream f m ()
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (() %1 -> Stream f m ()) %1 -> f () %1 -> f (Stream f m ())
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\() -> Int -> f () -> Stream f m ()
forall (m :: * -> *) (f :: * -> *).
(HasCallStack, Monad m, Functor f) =>
Int -> f () -> Stream f m ()
replicates (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) f ()
f) f ()
f
{-# INLINE replicates #-}
replicatesM :: forall f m . (Control.Monad m, Control.Functor f) =>
Int -> m (f ()) -> Stream f m ()
replicatesM :: forall (f :: * -> *) (m :: * -> *).
(Monad m, Functor f) =>
Int -> m (f ()) -> Stream f m ()
replicatesM = Int -> m (f ()) -> Stream f m ()
loop
where
loop :: Int -> m (f ()) -> Stream f m ()
loop :: Int -> m (f ()) -> Stream f m ()
loop Int
n m (f ())
mfstep
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = () -> Stream f m ()
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
| Bool
Prelude.otherwise = m (Stream f m ()) %1 -> Stream f m ()
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m ()) %1 -> Stream f m ())
%1 -> m (Stream f m ()) %1 -> Stream f m ()
forall a b. (a %1 -> b) %1 -> a %1 -> b
$
(f () %1 -> Stream f m ()) %1 -> m (f ()) %1 -> m (Stream f m ())
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (f (Stream f m ()) %1 -> Stream f m ()
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m ()) %1 -> Stream f m ())
%1 -> (f () %1 -> f (Stream f m ())) %1 -> f () %1 -> Stream f m ()
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (() %1 -> Stream f m ()) %1 -> f () %1 -> f (Stream f m ())
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\() -> Int -> m (f ()) -> Stream f m ()
loop (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) m (f ())
mfstep)) m (f ())
mfstep
{-# INLINABLE replicatesM #-}
unfold :: (Control.Monad m, Control.Functor f) =>
(s %1-> m (Either r (f s))) -> s %1-> Stream f m r
unfold :: forall (m :: * -> *) (f :: * -> *) s r.
(Monad m, Functor f) =>
(s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
unfold s %1 -> m (Either r (f s))
step s
state = (s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) s r.
(Monad m, Functor f) =>
(s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
unfold' s %1 -> m (Either r (f s))
step s
state
where
unfold' :: (Control.Monad m, Control.Functor f) =>
(s %1-> m (Either r (f s))) -> s %1-> Stream f m r
unfold' :: forall (m :: * -> *) (f :: * -> *) s r.
(Monad m, Functor f) =>
(s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
unfold' s %1 -> m (Either r (f s))
step s
state = m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m r) %1 -> Stream f m r)
%1 -> m (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Control.do
Either r (f s)
either <- s %1 -> m (Either r (f s))
step s
state
Either r (f s)
either Either r (f s)
%1 -> (Either r (f s) %1 -> m (Stream f m r))
%1 -> m (Stream f m r)
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Left r
r -> Stream f m r %1 -> m (Stream f m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f m r %1 -> m (Stream f m r))
%1 -> Stream f m r %1 -> m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Right (f s
fs) -> Stream f m r %1 -> m (Stream f m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f m r %1 -> m (Stream f m r))
%1 -> Stream f m r %1 -> m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m r) %1 -> Stream f m r)
%1 -> f (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (s %1 -> Stream f m r) %1 -> f s %1 -> f (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap ((s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) s r.
(Monad m, Functor f) =>
(s %1 -> m (Either r (f s))) -> s %1 -> Stream f m r
unfold s %1 -> m (Either r (f s))
step) f s
fs
{-# INLINABLE unfold #-}
untilJust :: forall f m r . (Control.Monad m, Data.Applicative f) =>
m (Maybe r) -> Stream f m r
untilJust :: forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Applicative f) =>
m (Maybe r) -> Stream f m r
untilJust m (Maybe r)
action = Stream f m r
loop
where
loop :: Stream f m r
loop :: Stream f m r
loop = m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m r) %1 -> Stream f m r)
%1 -> m (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Control.do
Maybe r
maybeVal <- m (Maybe r)
action
Maybe r
maybeVal Maybe r
%1 -> (Maybe r %1 -> m (Stream f m r)) %1 -> m (Stream f m r)
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Maybe r
Nothing -> Stream f m r %1 -> m (Stream f m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f m r %1 -> m (Stream f m r))
%1 -> Stream f m r %1 -> m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m r) %1 -> Stream f m r)
%1 -> f (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream f m r -> f (Stream f m r)
forall (f :: * -> *) a. Applicative f => a -> f a
Data.pure Stream f m r
loop
Just r
r -> Stream f m r %1 -> m (Stream f m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f m r %1 -> m (Stream f m r))
%1 -> Stream f m r %1 -> m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
{-# INLINABLE untilJust #-}
streamBuild ::
(forall b. (r %1-> b) -> (m b %1-> b) -> (f b %1-> b) -> b) -> Stream f m r
streamBuild :: forall r (m :: * -> *) (f :: * -> *).
(forall b. (r %1 -> b) -> (m b %1 -> b) -> (f b %1 -> b) -> b)
-> Stream f m r
streamBuild = \forall b. (r %1 -> b) -> (m b %1 -> b) -> (f b %1 -> b) -> b
phi -> (r %1 -> Stream f m r)
-> (m (Stream f m r) %1 -> Stream f m r)
-> (f (Stream f m r) %1 -> Stream f m r)
-> Stream f m r
forall b. (r %1 -> b) -> (m b %1 -> b) -> (f b %1 -> b) -> b
phi r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step
{-# INLINE streamBuild #-}
delays :: forall f r . (Data.Applicative f) => Double -> Stream f IO r
delays :: forall (f :: * -> *) r. Applicative f => Double -> Stream f IO r
delays Double
seconds = Stream f IO r
loop
where
loop :: Stream f IO r
loop :: Stream f IO r
loop = IO (Stream f IO r) %1 -> Stream f IO r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (IO (Stream f IO r) %1 -> Stream f IO r)
%1 -> IO (Stream f IO r) %1 -> Stream f IO r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Control.do
let delay :: Int
delay = Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
Prelude.truncate (Double
1000000 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
seconds))
() <- IO () %1 -> IO ()
forall a. IO a %1 -> IO a
fromSystemIO (IO () %1 -> IO ()) %1 -> IO () %1 -> IO ()
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Int -> IO ()
threadDelay Int
delay
Stream f IO r %1 -> IO (Stream f IO r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f IO r %1 -> IO (Stream f IO r))
%1 -> Stream f IO r %1 -> IO (Stream f IO r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f (Stream f IO r) %1 -> Stream f IO r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f IO r) %1 -> Stream f IO r)
%1 -> f (Stream f IO r) %1 -> Stream f IO r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream f IO r -> f (Stream f IO r)
forall (f :: * -> *) a. Applicative f => a -> f a
Data.pure Stream f IO r
loop
{-# INLINABLE delays #-}
maps :: forall f g m r . (Control.Monad m, Control.Functor f) =>
(forall x . f x %1-> g x) -> Stream f m r %1-> Stream g m r
maps :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
maps = (forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
Stream.maps
{-# INLINE maps #-}
mapsPost :: forall m f g r. (Control.Monad m, Control.Functor g) =>
(forall x. f x %1-> g x) -> Stream f m r %1-> Stream g m r
mapsPost :: forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
mapsPost = (forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
Stream.mapsPost
{-# INLINE mapsPost #-}
mapsM :: forall f g m r . (Control.Monad m, Control.Functor f) =>
(forall x. f x %1-> m (g x)) -> Stream f m r %1-> Stream g m r
mapsM :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mapsM forall x. f x %1 -> m (g x)
transform = Stream f m r %1 -> Stream g m r
loop where
loop :: Stream f m r %1-> Stream g m r
loop :: Stream f m r %1 -> Stream g m r
loop Stream f m r
stream = Stream f m r
stream Stream f m r
%1 -> (Stream f m r %1 -> Stream g m r) %1 -> Stream g m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> Stream g m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Step f (Stream f m r)
f -> m (Stream g m r) %1 -> Stream g m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream g m r) %1 -> Stream g m r)
%1 -> m (Stream g m r) %1 -> Stream g m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (g (Stream g m r) %1 -> Stream g m r)
%1 -> m (g (Stream g m r)) %1 -> m (Stream g m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap g (Stream g m r) %1 -> Stream g m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (m (g (Stream g m r)) %1 -> m (Stream g m r))
%1 -> m (g (Stream g m r)) %1 -> m (Stream g m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f (Stream g m r) %1 -> m (g (Stream g m r))
forall x. f x %1 -> m (g x)
transform (f (Stream g m r) %1 -> m (g (Stream g m r)))
%1 -> f (Stream g m r) %1 -> m (g (Stream g m r))
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream g m r)
%1 -> f (Stream f m r) %1 -> f (Stream g m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream f m r %1 -> Stream g m r
loop f (Stream f m r)
f
Effect m (Stream f m r)
m -> m (Stream g m r) %1 -> Stream g m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream g m r) %1 -> Stream g m r)
%1 -> m (Stream g m r) %1 -> Stream g m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream g m r)
%1 -> m (Stream f m r) %1 -> m (Stream g m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream f m r %1 -> Stream g m r
loop m (Stream f m r)
m
{-# INLINE mapsM #-}
mapsMPost :: forall m f g r. (Control.Monad m, Control.Functor g) =>
(forall x. f x %1-> m (g x)) -> Stream f m r %1-> Stream g m r
mapsMPost :: forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mapsMPost = (forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
Stream.mapsMPost
{-# INLINE mapsMPost #-}
mapped :: forall f g m r . (Control.Monad m, Control.Functor f) =>
(forall x. f x %1-> m (g x)) -> Stream f m r %1-> Stream g m r
mapped :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mapped = (forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mapsM
{-# INLINE mapped #-}
mappedPost :: forall m f g r. (Control.Monad m, Control.Functor g) =>
(forall x. f x %1-> m (g x)) -> Stream f m r %1-> Stream g m r
mappedPost :: forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mappedPost = (forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor g) =>
(forall x. f x %1 -> m (g x)) -> Stream f m r %1 -> Stream g m r
mapsMPost
{-# INLINE mappedPost #-}
hoistUnexposed :: forall f m n r. (Control.Monad m, Control.Functor f)
=> (forall a. m a %1-> n a) -> Stream f m r %1-> Stream f n r
hoistUnexposed :: forall (f :: * -> *) (m :: * -> *) (n :: * -> *) r.
(Monad m, Functor f) =>
(forall a. m a %1 -> n a) -> Stream f m r %1 -> Stream f n r
hoistUnexposed forall a. m a %1 -> n a
trans = Stream f m r %1 -> Stream f n r
loop where
loop :: Stream f m r %1-> Stream f n r
loop :: Stream f m r %1 -> Stream f n r
loop = n (Stream f n r) %1 -> Stream f n r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect
(n (Stream f n r) %1 -> Stream f n r)
%1 -> (m (Stream f n r) %1 -> n (Stream f n r))
%1 -> m (Stream f n r)
%1 -> Stream f n r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. m (Stream f n r) %1 -> n (Stream f n r)
forall a. m a %1 -> n a
trans
(m (Stream f n r) %1 -> Stream f n r)
%1 -> (Stream f m r %1 -> m (Stream f n r))
%1 -> Stream f m r
%1 -> Stream f n r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (r %1 -> m (Stream f n r))
-> (f (Stream f m r) %1 -> m (Stream f n r))
-> Stream f m r
%1 -> m (Stream f n r)
forall (f :: * -> *) (m :: * -> *) r a.
Monad m =>
(r %1 -> m a)
-> (f (Stream f m r) %1 -> m a) -> Stream f m r %1 -> m a
inspectC
(Stream f n r %1 -> m (Stream f n r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f n r %1 -> m (Stream f n r))
%1 -> (r %1 -> Stream f n r) %1 -> r %1 -> m (Stream f n r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. r %1 -> Stream f n r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return)
(Stream f n r %1 -> m (Stream f n r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f n r %1 -> m (Stream f n r))
%1 -> (f (Stream f n r) %1 -> Stream f n r)
%1 -> f (Stream f n r)
%1 -> m (Stream f n r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. f (Stream f n r) %1 -> Stream f n r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f n r) %1 -> m (Stream f n r))
%1 -> (f (Stream f m r) %1 -> f (Stream f n r))
%1 -> f (Stream f m r)
%1 -> m (Stream f n r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (Stream f m r %1 -> Stream f n r)
%1 -> f (Stream f m r) %1 -> f (Stream f n r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream f m r %1 -> Stream f n r
loop)
{-# INLINABLE hoistUnexposed #-}
inspectC :: forall f m r a. Control.Monad m =>
(r %1-> m a) -> (f (Stream f m r) %1-> m a) -> Stream f m r %1-> m a
inspectC :: forall (f :: * -> *) (m :: * -> *) r a.
Monad m =>
(r %1 -> m a)
-> (f (Stream f m r) %1 -> m a) -> Stream f m r %1 -> m a
inspectC r %1 -> m a
f f (Stream f m r) %1 -> m a
g = Stream f m r %1 -> m a
loop where
loop :: Stream f m r %1-> m a
loop :: Stream f m r %1 -> m a
loop (Return r
r) = r %1 -> m a
f r
r
loop (Step f (Stream f m r)
x) = f (Stream f m r) %1 -> m a
g f (Stream f m r)
x
loop (Effect m (Stream f m r)
m) = m (Stream f m r)
m m (Stream f m r) %1 -> (Stream f m r %1 -> m a) %1 -> m a
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream f m r %1 -> m a
loop
{-# INLINE inspectC #-}
groups :: forall f g m r .
(Control.Monad m, Control.Functor f, Control.Functor g) =>
Stream (Sum f g) m r %1-> Stream (Sum (Stream f m) (Stream g m)) m r
groups :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f, Functor g) =>
Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
groups = Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
loop
where
loop :: Stream (Sum f g) m r %1-> Stream (Sum (Stream f m) (Stream g m)) m r
loop :: Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
loop Stream (Sum f g) m r
str = Control.do
Either r (Sum f g (Stream (Sum f g) m r))
e <- m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream
(Sum (Stream f m) (Stream g m))
m
(Either r (Sum f g (Stream (Sum f g) m r)))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift (m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream
(Sum (Stream f m) (Stream g m))
m
(Either r (Sum f g (Stream (Sum f g) m r))))
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream
(Sum (Stream f m) (Stream g m))
m
(Either r (Sum f g (Stream (Sum f g) m r)))
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream (Sum f g) m r
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
forall (f :: * -> *) (m :: * -> *) r.
Monad m =>
Stream f m r %1 -> m (Either r (f (Stream f m r)))
inspect Stream (Sum f g) m r
str
Either r (Sum f g (Stream (Sum f g) m r))
e Either r (Sum f g (Stream (Sum f g) m r))
%1 -> (Either r (Sum f g (Stream (Sum f g) m r))
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Left r
r -> r %1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Right Sum f g (Stream (Sum f g) m r)
ostr -> Sum f g (Stream (Sum f g) m r)
ostr Sum f g (Stream (Sum f g) m r)
%1 -> (Sum f g (Stream (Sum f g) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
InR g (Stream (Sum f g) m r)
gstr -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR (Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r))
%1 -> Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream g m (Stream (Sum f g) m r)
%1 -> Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
loop (Stream g m (Stream (Sum f g) m r)
%1 -> Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r))
%1 -> Stream g m (Stream (Sum f g) m r)
%1 -> Stream g m (Stream (Sum (Stream f m) (Stream g m)) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
cleanR (Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (g (Stream (Sum f g) m r) %1 -> Sum f g (Stream (Sum f g) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g (Stream (Sum f g) m r)
gstr))
InL f (Stream (Sum f g) m r)
fstr -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL (Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r))
%1 -> Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Sum
(Stream f m)
(Stream g m)
(Stream (Sum (Stream f m) (Stream g m)) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r)
%1 -> Stream f m (Stream (Sum f g) m r)
%1 -> Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Sum f g) m r
%1 -> Stream (Sum (Stream f m) (Stream g m)) m r
loop (Stream f m (Stream (Sum f g) m r)
%1 -> Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r))
%1 -> Stream f m (Stream (Sum f g) m r)
%1 -> Stream f m (Stream (Sum (Stream f m) (Stream g m)) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
cleanL (Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream (Sum f g) m r) %1 -> Sum f g (Stream (Sum f g) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f (Stream (Sum f g) m r)
fstr))
cleanL :: Stream (Sum f g) m r %1-> Stream f m (Stream (Sum f g) m r)
cleanL :: Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
cleanL = Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
go
where
go :: Stream (Sum f g) m r %1-> Stream f m (Stream (Sum f g) m r)
go :: Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
go Stream (Sum f g) m r
s = Control.do
Either r (Sum f g (Stream (Sum f g) m r))
e <- m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream f m (Either r (Sum f g (Stream (Sum f g) m r)))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift (m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream f m (Either r (Sum f g (Stream (Sum f g) m r))))
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream f m (Either r (Sum f g (Stream (Sum f g) m r)))
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream (Sum f g) m r
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
forall (f :: * -> *) (m :: * -> *) r.
Monad m =>
Stream f m r %1 -> m (Either r (f (Stream f m r)))
inspect Stream (Sum f g) m r
s
Either r (Sum f g (Stream (Sum f g) m r))
e Either r (Sum f g (Stream (Sum f g) m r))
%1 -> (Either r (Sum f g (Stream (Sum f g) m r))
%1 -> Stream f m (Stream (Sum f g) m r))
%1 -> Stream f m (Stream (Sum f g) m r)
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Left r
r -> Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r))
%1 -> Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> Stream (Sum f g) m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Right (InL f (Stream (Sum f g) m r)
fstr) -> f (Stream f m (Stream (Sum f g) m r))
%1 -> Stream f m (Stream (Sum f g) m r)
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m (Stream (Sum f g) m r))
%1 -> Stream f m (Stream (Sum f g) m r))
%1 -> f (Stream f m (Stream (Sum f g) m r))
%1 -> Stream f m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r))
%1 -> f (Stream (Sum f g) m r)
%1 -> f (Stream f m (Stream (Sum f g) m r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
go f (Stream (Sum f g) m r)
fstr
Right (InR g (Stream (Sum f g) m r)
gstr) -> Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r))
%1 -> Stream (Sum f g) m r %1 -> Stream f m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (g (Stream (Sum f g) m r) %1 -> Sum f g (Stream (Sum f g) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR g (Stream (Sum f g) m r)
gstr)
cleanR :: Stream (Sum f g) m r %1-> Stream g m (Stream (Sum f g) m r)
cleanR :: Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
cleanR = Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
go
where
go :: Stream (Sum f g) m r %1-> Stream g m (Stream (Sum f g) m r)
go :: Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
go Stream (Sum f g) m r
s = Control.do
Either r (Sum f g (Stream (Sum f g) m r))
e <- m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream g m (Either r (Sum f g (Stream (Sum f g) m r)))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift (m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream g m (Either r (Sum f g (Stream (Sum f g) m r))))
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
%1 -> Stream g m (Either r (Sum f g (Stream (Sum f g) m r)))
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream (Sum f g) m r
%1 -> m (Either r (Sum f g (Stream (Sum f g) m r)))
forall (f :: * -> *) (m :: * -> *) r.
Monad m =>
Stream f m r %1 -> m (Either r (f (Stream f m r)))
inspect Stream (Sum f g) m r
s
Either r (Sum f g (Stream (Sum f g) m r))
e Either r (Sum f g (Stream (Sum f g) m r))
%1 -> (Either r (Sum f g (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r)
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Left r
r -> Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r))
%1 -> Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> Stream (Sum f g) m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Right (InL f (Stream (Sum f g) m r)
fstr) -> Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r))
%1 -> Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream (Sum f g) m r) %1 -> Sum f g (Stream (Sum f g) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL f (Stream (Sum f g) m r)
fstr)
Right (InR g (Stream (Sum f g) m r)
gstr) -> g (Stream g m (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r)
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step(g (Stream g m (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r))
%1 -> g (Stream g m (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r))
%1 -> g (Stream (Sum f g) m r)
%1 -> g (Stream g m (Stream (Sum f g) m r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Sum f g) m r %1 -> Stream g m (Stream (Sum f g) m r)
go g (Stream (Sum f g) m r)
gstr
{-# INLINABLE groups #-}
inspect :: forall f m r . Control.Monad m =>
Stream f m r %1-> m (Either r (f (Stream f m r)))
inspect :: forall (f :: * -> *) (m :: * -> *) r.
Monad m =>
Stream f m r %1 -> m (Either r (f (Stream f m r)))
inspect = Stream f m r %1 -> m (Either r (f (Stream f m r)))
loop
where
loop :: Stream f m r %1-> m (Either r (f (Stream f m r)))
loop :: Stream f m r %1 -> m (Either r (f (Stream f m r)))
loop Stream f m r
stream = Stream f m r
stream Stream f m r
%1 -> (Stream f m r %1 -> m (Either r (f (Stream f m r))))
%1 -> m (Either r (f (Stream f m r)))
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> Either r (f (Stream f m r)) %1 -> m (Either r (f (Stream f m r)))
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (r %1 -> Either r (f (Stream f m r))
forall a b. a -> Either a b
Left r
r)
Effect m (Stream f m r)
m -> m (Stream f m r)
m m (Stream f m r)
%1 -> (Stream f m r %1 -> m (Either r (f (Stream f m r))))
%1 -> m (Either r (f (Stream f m r)))
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream f m r %1 -> m (Either r (f (Stream f m r)))
loop
Step f (Stream f m r)
fs -> Either r (f (Stream f m r)) %1 -> m (Either r (f (Stream f m r)))
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (f (Stream f m r) %1 -> Either r (f (Stream f m r))
forall a b. b -> Either a b
Right f (Stream f m r)
fs)
{-# INLINABLE inspect #-}
splitsAt :: forall f m r .
(HasCallStack, Control.Monad m, Control.Functor f) =>
Int -> Stream f m r %1-> Stream f m (Stream f m r)
splitsAt :: forall (f :: * -> *) (m :: * -> *) r.
(HasCallStack, Monad m, Functor f) =>
Int -> Stream f m r %1 -> Stream f m (Stream f m r)
splitsAt Int
n Stream f m r
stream = Int -> Stream f m r %1 -> Stream f m (Stream f m r)
loop Int
n Stream f m r
stream
where
loop :: Int -> Stream f m r %1-> Stream f m (Stream f m r)
loop :: Int -> Stream f m r %1 -> Stream f m (Stream f m r)
loop Int
n Stream f m r
stream = case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
n Int
0 of
Ordering
LT -> [Char] -> Stream f m r %1 -> Stream f m (Stream f m r)
forall a. HasCallStack => [Char] -> a
Prelude.error [Char]
"splitsAt called with negative index" (Stream f m r %1 -> Stream f m (Stream f m r))
%1 -> Stream f m r %1 -> Stream f m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Stream f m r
stream
Ordering
EQ -> Stream f m r %1 -> Stream f m (Stream f m r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return Stream f m r
stream
Ordering
GT -> Stream f m r
stream Stream f m r
%1 -> (Stream f m r %1 -> Stream f m (Stream f m r))
%1 -> Stream f m (Stream f m r)
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> Stream f m r %1 -> Stream f m (Stream f m r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (Stream f m r %1 -> Stream f m (Stream f m r))
%1 -> Stream f m r %1 -> Stream f m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Effect m (Stream f m r)
m -> m (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r)
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r))
%1 -> m (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream f m (Stream f m r))
%1 -> m (Stream f m r) %1 -> m (Stream f m (Stream f m r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Int -> Stream f m r %1 -> Stream f m (Stream f m r)
loop Int
n) m (Stream f m r)
m
Step f (Stream f m r)
f -> f (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r)
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (f (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r))
%1 -> f (Stream f m (Stream f m r)) %1 -> Stream f m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream f m (Stream f m r))
%1 -> f (Stream f m r) %1 -> f (Stream f m (Stream f m r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Int -> Stream f m r %1 -> Stream f m (Stream f m r)
loop (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1)) f (Stream f m r)
f
{-# INLINABLE splitsAt #-}
chunksOf :: forall f m r .
(HasCallStack, Control.Monad m, Control.Functor f) =>
Int -> Stream f m r %1-> Stream (Stream f m) m r
chunksOf :: forall (f :: * -> *) (m :: * -> *) r.
(HasCallStack, Monad m, Functor f) =>
Int -> Stream f m r %1 -> Stream (Stream f m) m r
chunksOf Int
n Stream f m r
stream = Int -> Stream f m r %1 -> Stream (Stream f m) m r
loop Int
n Stream f m r
stream
where
loop :: Int -> Stream f m r %1-> Stream (Stream f m) m r
loop :: Int -> Stream f m r %1 -> Stream (Stream f m) m r
loop Int
_ (Return r
r) = r %1 -> Stream (Stream f m) m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
loop Int
n Stream f m r
stream = Stream f m (Stream (Stream f m) m r) %1 -> Stream (Stream f m) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (Stream f m (Stream (Stream f m) m r)
%1 -> Stream (Stream f m) m r)
%1 -> Stream f m (Stream (Stream f m) m r)
%1 -> Stream (Stream f m) m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream (Stream f m) m r)
%1 -> Stream f m (Stream f m r)
%1 -> Stream f m (Stream (Stream f m) m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Int -> Stream f m r %1 -> Stream (Stream f m) m r
loop Int
n) (Stream f m (Stream f m r)
%1 -> Stream f m (Stream (Stream f m) m r))
%1 -> Stream f m (Stream f m r)
%1 -> Stream f m (Stream (Stream f m) m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Int -> Stream f m r %1 -> Stream f m (Stream f m r)
forall (f :: * -> *) (m :: * -> *) r.
(HasCallStack, Monad m, Functor f) =>
Int -> Stream f m r %1 -> Stream f m (Stream f m r)
splitsAt Int
n Stream f m r
stream
{-# INLINABLE chunksOf #-}
concats :: forall f m r . (Control.Monad m, Control.Functor f) =>
Stream (Stream f m) m r %1-> Stream f m r
concats :: forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Stream (Stream f m) m r %1 -> Stream f m r
concats = Stream (Stream f m) m r %1 -> Stream f m r
loop
where
loop :: Stream (Stream f m) m r %1-> Stream f m r
loop :: Stream (Stream f m) m r %1 -> Stream f m r
loop Stream (Stream f m) m r
stream = Stream (Stream f m) m r
stream Stream (Stream f m) m r
%1 -> (Stream (Stream f m) m r %1 -> Stream f m r)
%1 -> Stream f m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Effect m (Stream (Stream f m) m r)
m -> m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m r) %1 -> Stream f m r)
%1 -> m (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Stream f m) m r %1 -> Stream f m r)
%1 -> m (Stream (Stream f m) m r) %1 -> m (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Stream f m) m r %1 -> Stream f m r
loop m (Stream (Stream f m) m r)
m
Step Stream f m (Stream (Stream f m) m r)
f -> Control.do
Stream f m r
rest <- (Stream (Stream f m) m r %1 -> Stream f m r)
%1 -> Stream f m (Stream (Stream f m) m r)
%1 -> Stream f m (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Stream f m) m r %1 -> Stream f m r
loop Stream f m (Stream (Stream f m) m r)
f
Stream f m r
rest
{-# INLINE concats #-}
intercalates :: forall t m r x .
(Control.Monad m, Control.Monad (t m), Control.MonadTrans t, Consumable x) =>
t m x -> Stream (t m) m r %1-> t m r
intercalates :: forall (t :: (* -> *) -> * -> *) (m :: * -> *) r x.
(Monad m, Monad (t m), MonadTrans t, Consumable x) =>
t m x -> Stream (t m) m r %1 -> t m r
intercalates t m x
sep = Stream (t m) m r %1 -> t m r
go0
where
go0 :: Stream (t m) m r %1-> t m r
go0 :: Stream (t m) m r %1 -> t m r
go0 Stream (t m) m r
f = Stream (t m) m r
f Stream (t m) m r %1 -> (Stream (t m) m r %1 -> t m r) %1 -> t m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> t m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (t m) m r)
m -> m (Stream (t m) m r) %1 -> t m (Stream (t m) m r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift m (Stream (t m) m r)
m t m (Stream (t m) m r)
%1 -> (Stream (t m) m r %1 -> t m r) %1 -> t m r
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream (t m) m r %1 -> t m r
go0
Step t m (Stream (t m) m r)
fstr -> Control.do
Stream (t m) m r
f' <- t m (Stream (t m) m r)
fstr
Stream (t m) m r %1 -> t m r
go1 Stream (t m) m r
f'
go1 :: Stream (t m) m r %1-> t m r
go1 :: Stream (t m) m r %1 -> t m r
go1 Stream (t m) m r
f = Stream (t m) m r
f Stream (t m) m r %1 -> (Stream (t m) m r %1 -> t m r) %1 -> t m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> t m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (t m) m r)
m -> m (Stream (t m) m r) %1 -> t m (Stream (t m) m r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift m (Stream (t m) m r)
m t m (Stream (t m) m r)
%1 -> (Stream (t m) m r %1 -> t m r) %1 -> t m r
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream (t m) m r %1 -> t m r
go1
Step t m (Stream (t m) m r)
fstr -> Control.do
x
x <- t m x
sep
() %1 -> t m ()
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (() %1 -> t m ()) %1 -> () %1 -> t m ()
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ x %1 -> ()
forall a. Consumable a => a %1 -> ()
consume x
x
Stream (t m) m r
f' <- t m (Stream (t m) m r)
fstr
Stream (t m) m r %1 -> t m r
go1 Stream (t m) m r
f'
{-# INLINABLE intercalates #-}
unzips :: forall f g m r .
(Control.Monad m, Control.Functor f, Control.Functor g) =>
Stream (Compose f g) m r %1-> Stream f (Stream g m) r
unzips :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f, Functor g) =>
Stream (Compose f g) m r %1 -> Stream f (Stream g m) r
unzips Stream (Compose f g) m r
str = Stream (Compose f g) m r
%1 -> (Compose f g (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r)
-> (m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r)
-> (r %1 -> Stream f (Stream g m) r)
-> Stream f (Stream g m) r
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroyExposed
Stream (Compose f g) m r
str
(\(Compose f (g (Stream f (Stream g m) r))
fgstr) -> f (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step ((g (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r)
%1 -> f (g (Stream f (Stream g m) r))
%1 -> f (Stream f (Stream g m) r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Stream g m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream g m (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r)
%1 -> (g (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r))
%1 -> g (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. g (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r)
forall (m :: * -> *) (f :: * -> *) r.
(Monad m, Functor f) =>
f r %1 -> Stream f m r
yields) f (g (Stream f (Stream g m) r))
fgstr))
(Stream g m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream g m (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r)
%1 -> (m (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r))
%1 -> m (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. m (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift)
r %1 -> Stream f (Stream g m) r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return
{-# INLINABLE unzips #-}
separate :: forall f g m r .
(Control.Monad m, Control.Functor f, Control.Functor g) =>
Stream (Sum f g) m r -> Stream f (Stream g m) r
separate :: forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f, Functor g) =>
Stream (Sum f g) m r -> Stream f (Stream g m) r
separate Stream (Sum f g) m r
str = Stream (Sum f g) m r
%1 -> (Sum f g (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r)
-> (m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r)
-> (r %1 -> Stream f (Stream g m) r)
-> Stream f (Stream g m) r
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroyExposed Stream (Sum f g) m r
str Sum f g (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
construct (Stream g m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream g m (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r)
%1 -> (m (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r))
%1 -> m (Stream f (Stream g m) r)
%1 -> Stream f (Stream g m) r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. m (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift) r %1 -> Stream f (Stream g m) r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return
where
construct :: Sum f g (Stream f (Stream g m) r) %1-> Stream f (Stream g m) r
construct :: Sum f g (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
construct (InL f (Stream f (Stream g m) r)
fss) = f (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step f (Stream f (Stream g m) r)
fss
construct (InR g (Stream f (Stream g m) r)
gss) = Stream g m (Stream f (Stream g m) r) %1 -> Stream f (Stream g m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (g (Stream f (Stream g m) r)
%1 -> Stream g m (Stream f (Stream g m) r)
forall (m :: * -> *) (f :: * -> *) r.
(Monad m, Functor f) =>
f r %1 -> Stream f m r
yields g (Stream f (Stream g m) r)
gss)
{-# INLINABLE separate #-}
unseparate :: (Control.Monad m, Control.Functor f, Control.Functor g) =>
Stream f (Stream g m) r -> Stream (Sum f g) m r
unseparate :: forall (m :: * -> *) (f :: * -> *) (g :: * -> *) r.
(Monad m, Functor f, Functor g) =>
Stream f (Stream g m) r -> Stream (Sum f g) m r
unseparate Stream f (Stream g m) r
str = Stream f (Stream g m) r
%1 -> (f (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r)
-> (Stream g m (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r)
-> (r %1 -> Stream (Sum f g) m r)
-> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroyExposed
Stream f (Stream g m) r
str
(Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (Sum f g (Stream (Sum f g) m r) %1 -> Stream (Sum f g) m r)
%1 -> (f (Stream (Sum f g) m r)
%1 -> Sum f g (Stream (Sum f g) m r))
%1 -> f (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. f (Stream (Sum f g) m r) %1 -> Sum f g (Stream (Sum f g) m r)
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). f a -> Sum f g a
InL)
(Stream (Sum f g) m (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m r
forall (m :: * -> *) a. Monad m => m (m a) %1 -> m a
Control.join (Stream (Sum f g) m (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m r)
%1 -> (Stream g m (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m (Stream (Sum f g) m r))
%1 -> Stream g m (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (forall x. g x %1 -> Sum f g x)
-> Stream g m (Stream (Sum f g) m r)
%1 -> Stream (Sum f g) m (Stream (Sum f g) m r)
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
maps forall x. g x %1 -> Sum f g x
forall {k} (f :: k -> *) (g :: k -> *) (a :: k). g a -> Sum f g a
InR)
r %1 -> Stream (Sum f g) m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return
{-# INLINABLE unseparate #-}
decompose :: forall f m r . (Control.Monad m, Control.Functor f) =>
Stream (Compose m f) m r %1-> Stream f m r
decompose :: forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Stream (Compose m f) m r %1 -> Stream f m r
decompose = Stream (Compose m f) m r %1 -> Stream f m r
loop where
loop :: Stream (Compose m f) m r %1-> Stream f m r
loop :: Stream (Compose m f) m r %1 -> Stream f m r
loop Stream (Compose m f) m r
stream = Stream (Compose m f) m r
stream Stream (Compose m f) m r
%1 -> (Stream (Compose m f) m r %1 -> Stream f m r)
%1 -> Stream f m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> Stream f m r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Effect m (Stream (Compose m f) m r)
m -> m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m r) %1 -> Stream f m r)
%1 -> m (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream (Compose m f) m r %1 -> Stream f m r)
%1 -> m (Stream (Compose m f) m r) %1 -> m (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Compose m f) m r %1 -> Stream f m r
loop m (Stream (Compose m f) m r)
m
Step (Compose m (f (Stream (Compose m f) m r))
mfs) -> m (Stream f m r) %1 -> Stream f m r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream f m r) %1 -> Stream f m r)
%1 -> m (Stream f m r) %1 -> Stream f m r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ Control.do
f (Stream (Compose m f) m r)
fstream <- m (f (Stream (Compose m f) m r))
mfs
Stream f m r %1 -> m (Stream f m r)
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Stream f m r %1 -> m (Stream f m r))
%1 -> Stream f m r %1 -> m (Stream f m r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f (Stream f m r) %1 -> Stream f m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step ((Stream (Compose m f) m r %1 -> Stream f m r)
%1 -> f (Stream (Compose m f) m r) %1 -> f (Stream f m r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream (Compose m f) m r %1 -> Stream f m r
loop f (Stream (Compose m f) m r)
fstream)
{-# INLINABLE decompose #-}
expand :: forall f m r g h . (Control.Monad m, Control.Functor f) =>
(forall a b. (g a %1-> b) -> f a %1-> h b) ->
Stream f m r %1-> Stream g (Stream h m) r
expand :: forall (f :: * -> *) (m :: * -> *) r (g :: * -> *) (h :: * -> *).
(Monad m, Functor f) =>
(forall a b. (g a %1 -> b) -> f a %1 -> h b)
-> Stream f m r %1 -> Stream g (Stream h m) r
expand forall a b. (g a %1 -> b) -> f a %1 -> h b
ext = Stream f m r %1 -> Stream g (Stream h m) r
loop where
loop :: Stream f m r %1-> Stream g (Stream h m) r
loop :: Stream f m r %1 -> Stream g (Stream h m) r
loop (Return r
r) = r %1 -> Stream g (Stream h m) r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
loop (Step f (Stream f m r)
f) = Stream h m (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (g (Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r))
-> f (Stream g (Stream h m) r)
%1 -> h (Stream h m (Stream g (Stream h m) r))
forall a b. (g a %1 -> b) -> f a %1 -> h b
ext (Stream g (Stream h m) r %1 -> Stream h m (Stream g (Stream h m) r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (Stream g (Stream h m) r
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> (g (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r)
%1 -> g (Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. g (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step) ((Stream f m r %1 -> Stream g (Stream h m) r)
%1 -> f (Stream f m r) %1 -> f (Stream g (Stream h m) r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream f m r %1 -> Stream g (Stream h m) r
loop f (Stream f m r)
f)
loop (Effect m (Stream f m r)
m) = Stream h m (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream h m (Stream g (Stream h m) r))
%1 -> m (Stream f m r)
%1 -> m (Stream h m (Stream g (Stream h m) r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Stream g (Stream h m) r %1 -> Stream h m (Stream g (Stream h m) r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (Stream g (Stream h m) r
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> (Stream f m r %1 -> Stream g (Stream h m) r)
%1 -> Stream f m r
%1 -> Stream h m (Stream g (Stream h m) r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. Stream f m r %1 -> Stream g (Stream h m) r
loop) m (Stream f m r)
m
{-# INLINABLE expand #-}
expandPost :: forall f m r g h . (Control.Monad m, Control.Functor g) =>
(forall a b. (g a %1-> b) -> f a %1-> h b) ->
Stream f m r %1-> Stream g (Stream h m) r
expandPost :: forall (f :: * -> *) (m :: * -> *) r (g :: * -> *) (h :: * -> *).
(Monad m, Functor g) =>
(forall a b. (g a %1 -> b) -> f a %1 -> h b)
-> Stream f m r %1 -> Stream g (Stream h m) r
expandPost forall a b. (g a %1 -> b) -> f a %1 -> h b
ext = Stream f m r %1 -> Stream g (Stream h m) r
loop where
loop :: Stream f m r %1-> Stream g (Stream h m) r
loop :: Stream f m r %1 -> Stream g (Stream h m) r
loop (Return r
r) = r %1 -> Stream g (Stream h m) r
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
loop (Step f (Stream f m r)
f) = Stream h m (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> h (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (g (Stream f m r) %1 -> Stream h m (Stream g (Stream h m) r))
-> f (Stream f m r) %1 -> h (Stream h m (Stream g (Stream h m) r))
forall a b. (g a %1 -> b) -> f a %1 -> h b
ext (Stream g (Stream h m) r %1 -> Stream h m (Stream g (Stream h m) r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (Stream g (Stream h m) r
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> (g (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r)
%1 -> g (Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. g (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step (g (Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> (g (Stream f m r) %1 -> g (Stream g (Stream h m) r))
%1 -> g (Stream f m r)
%1 -> Stream h m (Stream g (Stream h m) r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (Stream f m r %1 -> Stream g (Stream h m) r)
%1 -> g (Stream f m r) %1 -> g (Stream g (Stream h m) r)
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Stream f m r %1 -> Stream g (Stream h m) r
loop) f (Stream f m r)
f
loop (Effect m (Stream f m r)
m) = Stream h m (Stream g (Stream h m) r) %1 -> Stream g (Stream h m) r
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r)
%1 -> Stream h m (Stream g (Stream h m) r)
%1 -> Stream g (Stream h m) r
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect (m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> m (Stream h m (Stream g (Stream h m) r))
%1 -> Stream h m (Stream g (Stream h m) r)
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> Stream h m (Stream g (Stream h m) r))
%1 -> m (Stream f m r)
%1 -> m (Stream h m (Stream g (Stream h m) r))
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (Stream g (Stream h m) r %1 -> Stream h m (Stream g (Stream h m) r)
forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (Stream g (Stream h m) r
%1 -> Stream h m (Stream g (Stream h m) r))
%1 -> (Stream f m r %1 -> Stream g (Stream h m) r)
%1 -> Stream f m r
%1 -> Stream h m (Stream g (Stream h m) r)
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. Stream f m r %1 -> Stream g (Stream h m) r
loop) m (Stream f m r)
m
{-# INLINABLE expandPost #-}
mapsM_ :: (Control.Functor f, Control.Monad m) =>
(forall x . f x %1-> m x) -> Stream f m r %1-> m r
mapsM_ :: forall (f :: * -> *) (m :: * -> *) r.
(Functor f, Monad m) =>
(forall x. f x %1 -> m x) -> Stream f m r %1 -> m r
mapsM_ forall x. f x %1 -> m x
f = Stream m m r %1 -> m r
forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
run (Stream m m r %1 -> m r)
%1 -> (Stream f m r %1 -> Stream m m r)
%1 -> Stream f m r
%1 -> m r
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. (forall x. f x %1 -> m x) -> Stream f m r %1 -> Stream m m r
forall (f :: * -> *) (g :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
(forall x. f x %1 -> g x) -> Stream f m r %1 -> Stream g m r
maps forall x. f x %1 -> m x
f
{-# INLINE mapsM_ #-}
run :: Control.Monad m => Stream m m r %1-> m r
run :: forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
run = Stream m m r %1 -> m r
forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
loop
where
loop :: Control.Monad m => Stream m m r %1-> m r
loop :: forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
loop Stream m m r
stream = Stream m m r
stream Stream m m r %1 -> (Stream m m r %1 -> m r) %1 -> m r
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> r %1 -> m r
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream m m r)
m -> m (Stream m m r)
m m (Stream m m r) %1 -> (Stream m m r %1 -> m r) %1 -> m r
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream m m r %1 -> m r
forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
loop
Step m (Stream m m r)
mrest -> m (Stream m m r)
mrest m (Stream m m r) %1 -> (Stream m m r %1 -> m r) %1 -> m r
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream m m r %1 -> m r
forall (m :: * -> *) r. Monad m => Stream m m r %1 -> m r
loop
{-# INLINABLE run #-}
streamFold :: (Control.Functor f, Control.Monad m) =>
(r %1-> b) -> (m b %1-> b) -> (f b %1-> b) -> Stream f m r %1-> b
streamFold :: forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
(r %1 -> b)
-> (m b %1 -> b) -> (f b %1 -> b) -> Stream f m r %1 -> b
streamFold r %1 -> b
done m b %1 -> b
theEffect f b %1 -> b
construct Stream f m r
stream =
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroy Stream f m r
stream f b %1 -> b
construct m b %1 -> b
theEffect r %1 -> b
done
{-# INLINE streamFold #-}
iterT :: (Control.Functor f, Control.Monad m) =>
(f (m a) %1-> m a) -> Stream f m a %1-> m a
iterT :: forall (f :: * -> *) (m :: * -> *) a.
(Functor f, Monad m) =>
(f (m a) %1 -> m a) -> Stream f m a %1 -> m a
iterT f (m a) %1 -> m a
out Stream f m a
stream = Stream f m a
%1 -> (f (m a) %1 -> m a)
-> (m (m a) %1 -> m a)
-> (a %1 -> m a)
-> m a
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroyExposed Stream f m a
stream f (m a) %1 -> m a
out m (m a) %1 -> m a
forall (m :: * -> *) a. Monad m => m (m a) %1 -> m a
Control.join a %1 -> m a
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return
{-# INLINE iterT #-}
iterTM ::
( Control.Functor f, Control.Monad m
, Control.MonadTrans t, Control.Monad (t m)) =>
(f (t m a) %1-> t m a) -> Stream f m a %1-> t m a
iterTM :: forall (f :: * -> *) (m :: * -> *) (t :: (* -> *) -> * -> *) a.
(Functor f, Monad m, MonadTrans t, Monad (t m)) =>
(f (t m a) %1 -> t m a) -> Stream f m a %1 -> t m a
iterTM f (t m a) %1 -> t m a
out Stream f m a
stream =
Stream f m a
%1 -> (f (t m a) %1 -> t m a)
-> (m (t m a) %1 -> t m a)
-> (a %1 -> t m a)
-> t m a
forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroyExposed Stream f m a
stream f (t m a) %1 -> t m a
out (t m (t m a) %1 -> t m a
forall (m :: * -> *) a. Monad m => m (m a) %1 -> m a
Control.join (t m (t m a) %1 -> t m a)
%1 -> (m (t m a) %1 -> t m (t m a)) %1 -> m (t m a) %1 -> t m a
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. m (t m a) %1 -> t m (t m a)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift) a %1 -> t m a
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return
{-# INLINE iterTM #-}
destroy :: forall f m r b . (Control.Functor f, Control.Monad m) =>
Stream f m r %1-> (f b %1-> b) -> (m b %1-> b) -> (r %1-> b) -> b
destroy :: forall (f :: * -> *) (m :: * -> *) r b.
(Functor f, Monad m) =>
Stream f m r
%1 -> (f b %1 -> b) -> (m b %1 -> b) -> (r %1 -> b) -> b
destroy Stream f m r
stream0 f b %1 -> b
construct m b %1 -> b
theEffect r %1 -> b
done = m b %1 -> b
theEffect (Stream f m r %1 -> m b
loop Stream f m r
stream0)
where
loop :: Stream f m r %1-> m b
loop :: Stream f m r %1 -> m b
loop Stream f m r
stream = Stream f m r
stream Stream f m r %1 -> (Stream f m r %1 -> m b) %1 -> m b
forall a b. a %1 -> (a %1 -> b) %1 -> b
& \case
Return r
r -> b %1 -> m b
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (b %1 -> m b) %1 -> b %1 -> m b
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ r %1 -> b
done r
r
Effect m (Stream f m r)
m -> m (Stream f m r)
m m (Stream f m r) %1 -> (Stream f m r %1 -> m b) %1 -> m b
forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= Stream f m r %1 -> m b
loop
Step f (Stream f m r)
f -> b %1 -> m b
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (b %1 -> m b) %1 -> b %1 -> m b
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ f b %1 -> b
construct (f b %1 -> b) %1 -> f b %1 -> b
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ (Stream f m r %1 -> b) %1 -> f (Stream f m r) %1 -> f b
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (m b %1 -> b
theEffect (m b %1 -> b)
%1 -> (Stream f m r %1 -> m b) %1 -> Stream f m r %1 -> b
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. Stream f m r %1 -> m b
loop) f (Stream f m r)
f
{-# INLINABLE destroy #-}