{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_HADDOCK hide #-}
module Streaming.Linear.Internal.Produce
(
yield,
each',
unfoldr,
fromHandle,
readFile,
replicate,
replicateM,
replicateZip,
untilRight,
stdinLnN,
stdinLnUntil,
stdinLnUntilM,
stdinLnZip,
readLnN,
readLnUntil,
readLnUntilM,
readLnZip,
iterateN,
iterateZip,
iterateMN,
iterateMZip,
cycleN,
cycleZip,
enumFromN,
enumFromZip,
enumFromThenN,
enumFromThenZip,
)
where
import qualified Control.Functor.Linear as Control
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Unrestricted.Linear
import GHC.Stack
import Prelude.Linear (($), (&))
import Streaming.Linear.Internal.Consume (effects)
import Streaming.Linear.Internal.Process
import Streaming.Linear.Internal.Type
import qualified System.IO as System
import System.IO.Linear
import System.IO.Resource.Linear
import Prelude
( Bool (..),
Either (..),
Enum,
Eq (..),
FilePath,
Int,
Num (..),
Ord (..),
Read,
fromEnum,
otherwise,
toEnum,
)
import qualified Prelude
yield :: (Control.Monad m) => a -> Stream (Of a) m ()
yield :: forall (m :: * -> *) a. Monad m => a -> Stream (Of a) m ()
yield a
x = forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
x forall a b. a -> b -> Of a b
:> forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
{-# INLINE yield #-}
each' :: (Control.Monad m) => [a] -> Stream (Of a) m ()
each' :: forall (m :: * -> *) a. Monad m => [a] -> Stream (Of a) m ()
each' [a]
xs = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
Prelude.foldr (\a
a Stream (Of a) m ()
stream -> forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> Stream (Of a) m ()
stream) (forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()) [a]
xs
{-# INLINEABLE each' #-}
unfoldr ::
(Control.Monad m) =>
(s %1 -> m (Either r (Ur a, s))) ->
s %1 ->
Stream (Of a) m r
unfoldr :: forall (m :: * -> *) s r a.
Monad m =>
(s %1 -> m (Either r (Ur a, s))) -> s %1 -> Stream (Of a) m r
unfoldr s %1 -> m (Either r (Ur a, s))
step s
s = forall (m :: * -> *) s r a.
Monad m =>
(s %1 -> m (Either r (Ur a, s))) -> s %1 -> Stream (Of a) m r
unfoldr' s %1 -> m (Either r (Ur a, s))
step s
s
where
unfoldr' ::
(Control.Monad m) =>
(s %1 -> m (Either r (Ur a, s))) ->
s %1 ->
Stream (Of a) m r
unfoldr' :: forall (m :: * -> *) s r a.
Monad m =>
(s %1 -> m (Either r (Ur a, s))) -> s %1 -> Stream (Of a) m r
unfoldr' s %1 -> m (Either r (Ur a, s))
step 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
$
s %1 -> m (Either r (Ur a, s))
step s
s forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \case
Left r
r -> 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 r
r
Right (Ur a
a, s
s') ->
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> forall (m :: * -> *) s r a.
Monad m =>
(s %1 -> m (Either r (Ur a, s))) -> s %1 -> Stream (Of a) m r
unfoldr s %1 -> m (Either r (Ur a, s))
step s
s'
{-# INLINEABLE unfoldr #-}
fromHandle :: Handle %1 -> Stream (Of Text) RIO ()
fromHandle :: Handle %1 -> Stream (Of Text) RIO ()
fromHandle Handle
h = Handle %1 -> Stream (Of Text) RIO ()
loop Handle
h
where
loop :: Handle %1 -> Stream (Of Text) RIO ()
loop :: Handle %1 -> Stream (Of Text) RIO ()
loop Handle
h = Control.do
(Ur Bool
isEOF, Handle
h') <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Handle %1 -> RIO (Ur Bool, Handle)
hIsEOF Handle
h
case Bool
isEOF of
Bool
True -> Control.do
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Handle %1 -> RIO ()
hClose Handle
h'
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return ()
Bool
False -> Control.do
(Ur Text
text, Handle
h'') <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Handle %1 -> RIO (Ur Text, Handle)
hGetLine Handle
h'
forall (m :: * -> *) a. Monad m => a -> Stream (Of a) m ()
yield Text
text
Handle %1 -> Stream (Of Text) RIO ()
fromHandle Handle
h''
{-# INLINEABLE fromHandle #-}
readFile :: FilePath -> Stream (Of Text) RIO ()
readFile :: FilePath -> Stream (Of Text) RIO ()
readFile FilePath
path = Control.do
Handle
handle <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ FilePath -> IOMode -> RIO Handle
openFile FilePath
path IOMode
System.ReadMode
Handle %1 -> Stream (Of Text) RIO ()
fromHandle Handle
handle
replicate :: (HasCallStack, Control.Monad m) => Int -> a -> Stream (Of a) m ()
replicate :: forall (m :: * -> *) a.
(HasCallStack, Monad m) =>
Int -> a -> Stream (Of a) m ()
replicate Int
n a
a
| Int
n forall a. Ord a => a -> a -> Bool
< Int
0 = forall a. HasCallStack => FilePath -> a
Prelude.error FilePath
"Cannot replicate a stream of negative length"
| Bool
otherwise = forall (m :: * -> *) a. Monad m => Int -> a -> Stream (Of a) m ()
loop Int
n a
a
where
loop :: (Control.Monad m) => Int -> a -> Stream (Of a) m ()
loop :: forall (m :: * -> *) a. Monad m => Int -> a -> Stream (Of a) m ()
loop Int
n a
a
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
| Bool
otherwise = 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
$ 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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> forall (m :: * -> *) a. Monad m => Int -> a -> Stream (Of a) m ()
loop (Int
n forall a. Num a => a -> a -> a
- Int
1) a
a
{-# INLINEABLE replicate #-}
replicateM ::
(Control.Monad m) =>
Int ->
m (Ur a) ->
Stream (Of a) m ()
replicateM :: forall (m :: * -> *) a.
Monad m =>
Int -> m (Ur a) -> Stream (Of a) m ()
replicateM Int
n m (Ur a)
ma
| Int
n forall a. Ord a => a -> a -> Bool
< Int
0 = forall a. HasCallStack => FilePath -> a
Prelude.error FilePath
"Cannot replicate a stream of negative length"
| Bool
otherwise = forall (m :: * -> *) a.
Monad m =>
Int -> m (Ur a) -> Stream (Of a) m ()
loop Int
n m (Ur a)
ma
where
loop :: (Control.Monad m) => Int -> m (Ur a) -> Stream (Of a) m ()
loop :: forall (m :: * -> *) a.
Monad m =>
Int -> m (Ur a) -> Stream (Of a) m ()
loop Int
n m (Ur a)
ma
| Int
n forall a. Eq a => a -> a -> Bool
== Int
0 = forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return ()
| Bool
otherwise = 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 a
a <- m (Ur a)
ma
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> (forall (m :: * -> *) a.
Monad m =>
Int -> m (Ur a) -> Stream (Of a) m ()
replicateM (Int
n forall a. Num a => a -> a -> a
- Int
1) m (Ur a)
ma)
replicateZip ::
(Control.Monad m) =>
Stream (Of x) m r ->
a ->
Stream (Of (a, x)) m r
replicateZip :: forall (m :: * -> *) x r a.
Monad m =>
Stream (Of x) m r -> a -> Stream (Of (a, x)) m r
replicateZip Stream (Of x) m r
stream a
a = forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map ((,) a
a) Stream (Of x) m r
stream
{-# INLINEABLE replicateZip #-}
untilRight ::
forall m a r.
(Control.Monad m) =>
m (Either (Ur a) r) ->
Stream (Of a) m r
untilRight :: forall (m :: * -> *) a r.
Monad m =>
m (Either (Ur a) r) -> Stream (Of a) m r
untilRight m (Either (Ur a) r)
mEither = forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect m (Stream (Of a) m r)
loop
where
loop :: m (Stream (Of a) m r)
loop :: m (Stream (Of a) m r)
loop = Control.do
Either (Ur a) r
either <- m (Either (Ur a) r)
mEither
Either (Ur a) r
either forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Left (Ur 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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> (forall (m :: * -> *) a r.
Monad m =>
m (Either (Ur a) r) -> Stream (Of a) m r
untilRight m (Either (Ur a) r)
mEither)
Right r
r -> 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 r
r
{-# INLINEABLE untilRight #-}
data AffineStream f m r where
AffineStream ::
x %1 ->
(x %1 -> m (Either (f x) r)) ->
(x %1 -> m r) ->
AffineStream f m r
take ::
forall f m r.
(Control.Monad m, Control.Functor f) =>
Int ->
AffineStream f m r %1 ->
Stream f m r
take :: forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take = Int -> AffineStream f m r %1 -> Stream f m r
loop
where
loop :: Int -> AffineStream f m r %1 -> Stream f m r
loop :: Int -> AffineStream f m r %1 -> Stream f m r
loop Int
n (AffineStream x
s x %1 -> m (Either (f x) r)
step x %1 -> m r
end)
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 = 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
$ forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap 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
$ x %1 -> m r
end x
s
| Bool
otherwise = 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
Either (f x) r
next <- x %1 -> m (Either (f x) r)
step x
s
Either (f x) r
next forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Right r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r)
Left f x
fx ->
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\x
x -> Int -> AffineStream f m r %1 -> Stream f m r
loop (Int
n forall a. Num a => a -> a -> a
- Int
1) (forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream x
x x %1 -> m (Either (f x) r)
step x %1 -> m r
end)) f x
fx
{-# INLINEABLE take #-}
untilM ::
forall a m r.
(Control.Monad m) =>
(a -> m Bool) ->
AffineStream (Of a) m r %1 ->
Stream (Of a) m r
untilM :: forall a (m :: * -> *) r.
Monad m =>
(a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
untilM = (a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop
where
loop :: (a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop :: (a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop a -> m Bool
test (AffineStream x
s x %1 -> m (Either (Of a x) r)
step x %1 -> m r
end) = 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
Either (Of a x) r
next <- x %1 -> m (Either (Of a x) r)
step x
s
Either (Of a x) r
next forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Right r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r)
Left (a
a :> x
next) -> Control.do
Bool
testResult <- a -> m Bool
test a
a
Bool
testResult forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Bool
False ->
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
a
a forall a b. a -> b -> Of a b
:> (a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop a -> m Bool
test (forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream x
next x %1 -> m (Either (Of a x) r)
step x %1 -> m r
end)
Bool
True -> forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap 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
$ x %1 -> m r
end x
next
{-# INLINEABLE untilM #-}
until ::
forall a m r.
(Control.Monad m) =>
(a -> Bool) ->
AffineStream (Of a) m r %1 ->
Stream (Of a) m r
until :: forall a (m :: * -> *) r.
Monad m =>
(a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
until = (a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop
where
loop :: (a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop :: (a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop a -> Bool
test (AffineStream x
s x %1 -> m (Either (Of a x) r)
step x %1 -> m r
end) = 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
Either (Of a x) r
next <- x %1 -> m (Either (Of a x) r)
step x
s
Either (Of a x) r
next forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Right r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r)
Left (a
a :> x
next) -> case a -> Bool
test a
a of
Bool
True -> forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap 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
$ x %1 -> m r
end x
next
Bool
False ->
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
a
a forall a b. a -> b -> Of a b
:> (a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
loop a -> Bool
test (forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream x
next x %1 -> m (Either (Of a x) r)
step x %1 -> m r
end)
{-# INLINEABLE until #-}
zip ::
forall a x m r1 r2.
(Control.Monad m) =>
Stream (Of x) m r1 %1 ->
AffineStream (Of a) m r2 %1 ->
Stream (Of (x, a)) m (r1, r2)
zip :: forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip = Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
loop
where
loop ::
Stream (Of x) m r1 %1 ->
AffineStream (Of a) m r2 %1 ->
Stream (Of (x, a)) m (r1, r2)
loop :: Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
loop Stream (Of x) m r1
stream (AffineStream x
s x %1 -> m (Either (Of a x) r2)
step x %1 -> m r2
end) =
Stream (Of x) m r1
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r1
r1 ->
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
$
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\r2
r2 -> 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
$ (r1
r1, r2
r2)) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
x %1 -> m r2
end x
s
Effect m (Stream (Of x) m r1)
m ->
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
$
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\Stream (Of x) m r1
str -> Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
loop Stream (Of x) m r1
str (forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream x
s x %1 -> m (Either (Of a x) r2)
step x %1 -> m r2
end)) m (Stream (Of x) m r1)
m
Step (x
x :> Stream (Of x) m r1
rest) -> 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
Either (Of a x) r2
next <- x %1 -> m (Either (Of a x) r2)
step x
s
Either (Of a x) r2
next forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Right r2
r2 -> Control.do
r1
r1 <- forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of x) m r1
rest
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return (r1
r1, r2
r2))
Left (a
a :> x
rest') ->
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 (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
(x
x, a
a) forall a b. a -> b -> Of a b
:> Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
loop Stream (Of x) m r1
rest (forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream x
rest' x %1 -> m (Either (Of a x) r2)
step x %1 -> m r2
end)
{-# INLINEABLE zip #-}
stdinLn :: AffineStream (Of Text) IO ()
stdinLn :: AffineStream (Of Text) IO ()
stdinLn = forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream () () %1 -> IO (Either (Of Text ()) ())
getALine forall (f :: * -> *) a. Applicative f => a %1 -> f a
Control.pure
where
getALine :: () %1 -> IO (Either (Of Text ()) ())
getALine :: () %1 -> IO (Either (Of Text ()) ())
getALine () = Control.do
Ur FilePath
line <- forall a. IO a -> IO (Ur a)
fromSystemIOU IO FilePath
System.getLine
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 a b. a -> Either a b
Left (FilePath -> Text
Text.pack FilePath
line forall a b. a -> b -> Of a b
:> ())
readLn :: (Read a) => AffineStream (Of a) IO ()
readLn :: forall a. Read a => AffineStream (Of a) IO ()
readLn = forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream () forall a. Read a => () %1 -> IO (Either (Of a ()) ())
readALine forall (f :: * -> *) a. Applicative f => a %1 -> f a
Control.pure
where
readALine :: (Read a) => () %1 -> IO (Either (Of a ()) ())
readALine :: forall a. Read a => () %1 -> IO (Either (Of a ()) ())
readALine () = Control.do
Ur FilePath
line <- forall a. IO a -> IO (Ur a)
fromSystemIOU IO FilePath
System.getLine
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 a b. a -> Either a b
Left (forall a. Read a => FilePath -> a
Prelude.read FilePath
line forall a b. a -> b -> Of a b
:> ())
iterate ::
forall a m.
(Control.Monad m) =>
a ->
(a -> a) ->
AffineStream (Of a) m ()
iterate :: forall a (m :: * -> *).
Monad m =>
a -> (a -> a) -> AffineStream (Of a) m ()
iterate a
a a -> a
step =
forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream (forall a. a -> Ur a
Ur a
a) Ur a %1 -> m (Either (Of a (Ur a)) ())
stepper (\Ur a
x -> 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 a. Consumable a => a %1 -> ()
consume Ur a
x)
where
stepper :: Ur a %1 -> m (Either (Of a (Ur a)) ())
stepper :: Ur a %1 -> m (Either (Of a (Ur a)) ())
stepper (Ur 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 a b. a -> Either a b
Left forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
a
a forall a b. a -> b -> Of a b
:> forall a. a -> Ur a
Ur (a -> a
step a
a)
iterateM ::
forall a m.
(Control.Monad m) =>
m (Ur a) ->
(a -> m (Ur a)) ->
AffineStream (Of a) m ()
iterateM :: forall a (m :: * -> *).
Monad m =>
m (Ur a) -> (a -> m (Ur a)) -> AffineStream (Of a) m ()
iterateM m (Ur a)
ma a -> m (Ur a)
step =
forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream m (Ur a)
ma m (Ur a) %1 -> m (Either (Of a (m (Ur a))) ())
stepper (forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap forall a. Consumable a => a %1 -> ()
consume)
where
stepper :: m (Ur a) %1 -> m (Either (Of a (m (Ur a))) ())
stepper :: m (Ur a) %1 -> m (Either (Of a (m (Ur a))) ())
stepper m (Ur a)
ma = Control.do
Ur a
a <- m (Ur a)
ma
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 a b. a -> Either a b
Left forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a
a forall a b. a -> b -> Of a b
:> (a -> m (Ur a)
step a
a)
cycle ::
forall a m r.
(Control.Monad m, Consumable r) =>
Stream (Of a) m r ->
AffineStream (Of a) m r
cycle :: forall a (m :: * -> *) r.
(Monad m, Consumable r) =>
Stream (Of a) m r -> AffineStream (Of a) m r
cycle Stream (Of a) m r
stream =
forall x (m :: * -> *) (f :: * -> *) r.
x
-> (x %1 -> m (Either (f x) r))
-> (x %1 -> m r)
-> AffineStream f m r
AffineStream (forall a. a -> Ur a
Ur Stream (Of a) m r
stream, Stream (Of a) m r
stream) forall (f :: * -> *).
Functor f =>
(Ur (Stream f m r), Stream f m r)
%1 -> m (Either (f (Ur (Stream f m r), Stream f m r)) r)
stepStream (Ur (Stream (Of a) m r), Stream (Of a) m r) %1 -> m r
leftoverEffects
where
leftoverEffects ::
(Ur (Stream (Of a) m r), Stream (Of a) m r) %1 -> m r
leftoverEffects :: (Ur (Stream (Of a) m r), Stream (Of a) m r) %1 -> m r
leftoverEffects (Ur Stream (Of a) m r
_, Stream (Of a) m r
str) = forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
str
stepStream ::
(Control.Functor f) =>
(Ur (Stream f m r), Stream f m r) %1 ->
m (Either (f (Ur (Stream f m r), Stream f m r)) r)
stepStream :: forall (f :: * -> *).
Functor f =>
(Ur (Stream f m r), Stream f m r)
%1 -> m (Either (f (Ur (Stream f m r), Stream f m r)) r)
stepStream (Ur Stream f m r
s, Stream f m r
str) =
Stream f m r
str forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (f :: * -> *).
Functor f =>
(Ur (Stream f m r), Stream f m r)
%1 -> m (Either (f (Ur (Stream f m r), Stream f m r)) r)
stepStream (forall a. a -> Ur a
Ur Stream f m r
s, Stream f m r
s)
Effect m (Stream f m r)
m ->
m (Stream f m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= (\Stream f m r
stream -> forall (f :: * -> *).
Functor f =>
(Ur (Stream f m r), Stream f m r)
%1 -> m (Either (f (Ur (Stream f m r), Stream f m r)) r)
stepStream (forall a. a -> Ur a
Ur Stream f m r
s, Stream f m r
stream))
Step f (Stream f m r)
f ->
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 a b. a -> Either a b
Left forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap ((,) (forall a. a -> Ur a
Ur Stream f m r
s)) f (Stream f m r)
f
enumFrom :: (Control.Monad m, Enum e) => e -> AffineStream (Of e) m ()
enumFrom :: forall (m :: * -> *) e.
(Monad m, Enum e) =>
e -> AffineStream (Of e) m ()
enumFrom e
e = forall a (m :: * -> *).
Monad m =>
a -> (a -> a) -> AffineStream (Of a) m ()
iterate e
e forall a. Enum a => a -> a
Prelude.succ
enumFromThen ::
forall e m.
(Control.Monad m, Enum e) =>
e ->
e ->
AffineStream (Of e) m ()
enumFromThen :: forall e (m :: * -> *).
(Monad m, Enum e) =>
e -> e -> AffineStream (Of e) m ()
enumFromThen e
e e
e' = forall a (m :: * -> *).
Monad m =>
a -> (a -> a) -> AffineStream (Of a) m ()
iterate e
e e -> e
enumStep
where
enumStep :: e -> e
enumStep :: e -> e
enumStep e
enum =
forall a. Enum a => Int -> a
toEnum forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$
(forall a. Enum a => a -> Int
fromEnum e
enum) forall a. Num a => a -> a -> a
+ ((forall a. Enum a => a -> Int
fromEnum e
e') forall a. Num a => a -> a -> a
- (forall a. Enum a => a -> Int
fromEnum e
e))
stdinLnN :: Int -> Stream (Of Text) IO ()
stdinLnN :: Int -> Stream (Of Text) IO ()
stdinLnN Int
n = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n AffineStream (Of Text) IO ()
stdinLn
{-# INLINE stdinLnN #-}
stdinLnUntilM :: (Text -> IO Bool) -> Stream (Of Text) IO ()
stdinLnUntilM :: (Text -> IO Bool) -> Stream (Of Text) IO ()
stdinLnUntilM Text -> IO Bool
test = forall a (m :: * -> *) r.
Monad m =>
(a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
untilM Text -> IO Bool
test AffineStream (Of Text) IO ()
stdinLn
{-# INLINE stdinLnUntilM #-}
stdinLnUntil :: (Text -> Bool) -> Stream (Of Text) IO ()
stdinLnUntil :: (Text -> Bool) -> Stream (Of Text) IO ()
stdinLnUntil Text -> Bool
test = forall a (m :: * -> *) r.
Monad m =>
(a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
until Text -> Bool
test AffineStream (Of Text) IO ()
stdinLn
{-# INLINE stdinLnUntil #-}
stdinLnZip :: Stream (Of x) IO r %1 -> Stream (Of (x, Text)) IO r
stdinLnZip :: forall x r. Stream (Of x) IO r %1 -> Stream (Of (x, Text)) IO r
stdinLnZip Stream (Of x) IO r
stream = forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of x) IO r
stream AffineStream (Of Text) IO ()
stdinLn
{-# INLINE stdinLnZip #-}
readLnN :: (Read a) => Int -> Stream (Of a) IO ()
readLnN :: forall a. Read a => Int -> Stream (Of a) IO ()
readLnN Int
n = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a. Read a => AffineStream (Of a) IO ()
readLn
{-# INLINE readLnN #-}
readLnUntilM :: (Read a) => (a -> IO Bool) -> Stream (Of a) IO ()
readLnUntilM :: forall a. Read a => (a -> IO Bool) -> Stream (Of a) IO ()
readLnUntilM a -> IO Bool
test = forall a (m :: * -> *) r.
Monad m =>
(a -> m Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
untilM a -> IO Bool
test forall a. Read a => AffineStream (Of a) IO ()
readLn
{-# INLINE readLnUntilM #-}
readLnUntil :: (Read a) => (a -> Bool) -> Stream (Of a) IO ()
readLnUntil :: forall a. Read a => (a -> Bool) -> Stream (Of a) IO ()
readLnUntil a -> Bool
test = forall a (m :: * -> *) r.
Monad m =>
(a -> Bool) -> AffineStream (Of a) m r %1 -> Stream (Of a) m r
until a -> Bool
test forall a. Read a => AffineStream (Of a) IO ()
readLn
{-# INLINE readLnUntil #-}
readLnZip :: (Read a) => Stream (Of x) IO r %1 -> Stream (Of (x, a)) IO r
readLnZip :: forall a x r.
Read a =>
Stream (Of x) IO r %1 -> Stream (Of (x, a)) IO r
readLnZip Stream (Of x) IO r
stream = forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of x) IO r
stream forall a. Read a => AffineStream (Of a) IO ()
readLn
{-# INLINE readLnZip #-}
iterateN :: (Control.Monad m) => Int -> (a -> a) -> a -> Stream (Of a) m ()
iterateN :: forall (m :: * -> *) a.
Monad m =>
Int -> (a -> a) -> a -> Stream (Of a) m ()
iterateN Int
n a -> a
step a
a = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *).
Monad m =>
a -> (a -> a) -> AffineStream (Of a) m ()
iterate a
a a -> a
step
{-# INLINE iterateN #-}
iterateZip ::
(Control.Monad m) =>
Stream (Of x) m r ->
(a -> a) ->
a ->
Stream (Of (x, a)) m r
iterateZip :: forall (m :: * -> *) x r a.
Monad m =>
Stream (Of x) m r -> (a -> a) -> a -> Stream (Of (x, a)) m r
iterateZip Stream (Of x) m r
stream a -> a
step a
a =
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of x) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *).
Monad m =>
a -> (a -> a) -> AffineStream (Of a) m ()
iterate a
a a -> a
step
{-# INLINE iterateZip #-}
iterateMN ::
(Control.Monad m) =>
Int ->
(a -> m (Ur a)) ->
m (Ur a) ->
Stream (Of a) m ()
iterateMN :: forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m (Ur a)) -> m (Ur a) -> Stream (Of a) m ()
iterateMN Int
n a -> m (Ur a)
step m (Ur a)
ma = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *).
Monad m =>
m (Ur a) -> (a -> m (Ur a)) -> AffineStream (Of a) m ()
iterateM m (Ur a)
ma a -> m (Ur a)
step
{-# INLINE iterateMN #-}
iterateMZip ::
(Control.Monad m) =>
Stream (Of x) m r %1 ->
(a -> m (Ur a)) ->
m (Ur a) ->
Stream (Of (x, a)) m r
iterateMZip :: forall (m :: * -> *) x r a.
Monad m =>
Stream (Of x) m r
%1 -> (a -> m (Ur a)) -> m (Ur a) -> Stream (Of (x, a)) m r
iterateMZip Stream (Of x) m r
stream a -> m (Ur a)
step m (Ur a)
ma =
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of x) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *).
Monad m =>
m (Ur a) -> (a -> m (Ur a)) -> AffineStream (Of a) m ()
iterateM m (Ur a)
ma a -> m (Ur a)
step
{-# INLINE iterateMZip #-}
cycleN ::
(Control.Monad m, Consumable r) =>
Int ->
Stream (Of a) m r ->
Stream (Of a) m r
cycleN :: forall (m :: * -> *) r a.
(Monad m, Consumable r) =>
Int -> Stream (Of a) m r -> Stream (Of a) m r
cycleN Int
n Stream (Of a) m r
stream = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *) r.
(Monad m, Consumable r) =>
Stream (Of a) m r -> AffineStream (Of a) m r
cycle Stream (Of a) m r
stream
{-# INLINE cycleN #-}
cycleZip ::
(Control.Monad m, Consumable s) =>
Stream (Of a) m r %1 ->
Stream (Of b) m s ->
Stream (Of (a, b)) m (r, s)
cycleZip :: forall (m :: * -> *) s a r b.
(Monad m, Consumable s) =>
Stream (Of a) m r
%1 -> Stream (Of b) m s -> Stream (Of (a, b)) m (r, s)
cycleZip Stream (Of a) m r
str Stream (Of b) m s
stream = forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of a) m r
str forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *) r.
(Monad m, Consumable r) =>
Stream (Of a) m r -> AffineStream (Of a) m r
cycle Stream (Of b) m s
stream
{-# INLINE cycleZip #-}
enumFromThenN :: (Control.Monad m, Enum e) => Int -> e -> e -> Stream (Of e) m ()
enumFromThenN :: forall (m :: * -> *) e.
(Monad m, Enum e) =>
Int -> e -> e -> Stream (Of e) m ()
enumFromThenN Int
n e
e e
e' = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall e (m :: * -> *).
(Monad m, Enum e) =>
e -> e -> AffineStream (Of e) m ()
enumFromThen e
e e
e'
{-# INLINE enumFromThenN #-}
enumFromThenZip ::
(Control.Monad m, Enum e) =>
Stream (Of a) m r %1 ->
e ->
e ->
Stream (Of (a, e)) m r
enumFromThenZip :: forall (m :: * -> *) e a r.
(Monad m, Enum e) =>
Stream (Of a) m r %1 -> e -> e -> Stream (Of (a, e)) m r
enumFromThenZip Stream (Of a) m r
stream e
e e
e' =
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall e (m :: * -> *).
(Monad m, Enum e) =>
e -> e -> AffineStream (Of e) m ()
enumFromThen e
e e
e'
{-# INLINE enumFromThenZip #-}
enumFromN :: (Control.Monad m, Enum e) => Int -> e -> Stream (Of e) m ()
enumFromN :: forall (m :: * -> *) e.
(Monad m, Enum e) =>
Int -> e -> Stream (Of e) m ()
enumFromN Int
n e
e = forall (f :: * -> *) (m :: * -> *) r.
(Monad m, Functor f) =>
Int -> AffineStream f m r %1 -> Stream f m r
take Int
n forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) e.
(Monad m, Enum e) =>
e -> AffineStream (Of e) m ()
enumFrom e
e
{-# INLINE enumFromN #-}
enumFromZip ::
(Control.Monad m, Enum e) =>
Stream (Of a) m r %1 ->
e ->
Stream (Of (a, e)) m r
enumFromZip :: forall (m :: * -> *) e a r.
(Monad m, Enum e) =>
Stream (Of a) m r %1 -> e -> Stream (Of (a, e)) m r
enumFromZip Stream (Of a) m r
str e
e =
forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (\(r
r, ()) -> r
r) forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a x (m :: * -> *) r1 r2.
Monad m =>
Stream (Of x) m r1
%1 -> AffineStream (Of a) m r2 %1 -> Stream (Of (x, a)) m (r1, r2)
zip Stream (Of a) m r
str forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) e.
(Monad m, Enum e) =>
e -> AffineStream (Of e) m ()
enumFrom e
e
{-# INLINE enumFromZip #-}