{-# LANGUAGE CPP, ExistentialQuantification, MultiParamTypeClasses, FlexibleInstances, Rank2Types, BangPatterns, KindSignatures, GADTs, ScopedTypeVariables #-}
module Data.Vector.Fusion.Stream.Monadic (
Stream(..), Step(..), SPEC(..),
length, null,
empty, singleton, cons, snoc, replicate, replicateM, generate, generateM, (++),
head, last, (!!), (!?),
slice, init, tail, take, drop,
map, mapM, mapM_, trans, unbox, concatMap, flatten,
indexed, indexedR, zipWithM_,
zipWithM, zipWith3M, zipWith4M, zipWith5M, zipWith6M,
zipWith, zipWith3, zipWith4, zipWith5, zipWith6,
zip, zip3, zip4, zip5, zip6,
eqBy, cmpBy,
filter, filterM, uniq, mapMaybe, takeWhile, takeWhileM, dropWhile, dropWhileM,
elem, notElem, find, findM, findIndex, findIndexM,
foldl, foldlM, foldl1, foldl1M, foldM, fold1M,
foldl', foldlM', foldl1', foldl1M', foldM', fold1M',
foldr, foldrM, foldr1, foldr1M,
and, or, concatMapM,
unfoldr, unfoldrM,
unfoldrN, unfoldrNM,
iterateN, iterateNM,
prescanl, prescanlM, prescanl', prescanlM',
postscanl, postscanlM, postscanl', postscanlM',
scanl, scanlM, scanl', scanlM',
scanl1, scanl1M, scanl1', scanl1M',
enumFromStepN, enumFromTo, enumFromThenTo,
toList, fromList, fromListN
) where
import Data.Vector.Fusion.Util ( Box(..) )
import Data.Char ( ord )
import GHC.Base ( unsafeChr )
import Control.Monad ( liftM )
import Prelude hiding ( length, null,
replicate, (++),
head, last, (!!),
init, tail, take, drop,
map, mapM, mapM_, concatMap,
zipWith, zipWith3, zip, zip3,
filter, takeWhile, dropWhile,
elem, notElem,
foldl, foldl1, foldr, foldr1,
and, or,
scanl, scanl1,
enumFromTo, enumFromThenTo )
import Data.Int ( Int8, Int16, Int32 )
import Data.Word ( Word8, Word16, Word32, Word64 )
#if !MIN_VERSION_base(4,8,0)
import Data.Word ( Word8, Word16, Word32, Word, Word64 )
#endif
#if __GLASGOW_HASKELL__ >= 708
import GHC.Types ( SPEC(..) )
#elif __GLASGOW_HASKELL__ >= 700
import GHC.Exts ( SpecConstrAnnotation(..) )
#endif
#include "vector.h"
#include "MachDeps.h"
#if WORD_SIZE_IN_BITS > 32
import Data.Int ( Int64 )
#endif
#if __GLASGOW_HASKELL__ < 708
data SPEC = SPEC | SPEC2
#if __GLASGOW_HASKELL__ >= 700
{-# ANN type SPEC ForceSpecConstr #-}
#endif
#endif
emptyStream :: String
{-# NOINLINE emptyStream #-}
emptyStream :: String
emptyStream = "empty stream"
#define EMPTY_STREAM (\state -> ERROR state emptyStream)
data Step s a where
Yield :: a -> s -> Step s a
Skip :: s -> Step s a
Done :: Step s a
instance Functor (Step s) where
{-# INLINE fmap #-}
fmap :: (a -> b) -> Step s a -> Step s b
fmap f :: a -> b
f (Yield x :: a
x s :: s
s) = b -> s -> Step s b
forall a s. a -> s -> Step s a
Yield (a -> b
f a
x) s
s
fmap _ (Skip s :: s
s) = s -> Step s b
forall s a. s -> Step s a
Skip s
s
fmap _ Done = Step s b
forall s a. Step s a
Done
data Stream m a = forall s. Stream (s -> m (Step s a)) s
length :: Monad m => Stream m a -> m Int
{-# INLINE_FUSED length #-}
length :: Stream m a -> m Int
length = (Int -> a -> Int) -> Int -> Stream m a -> m Int
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> a) -> a -> Stream m b -> m a
foldl' (\n :: Int
n _ -> Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) 0
null :: Monad m => Stream m a -> m Bool
{-# INLINE_FUSED null #-}
null :: Stream m a -> m Bool
null (Stream step :: s -> m (Step s a)
step t :: s
t) = s -> m Bool
null_loop s
t
where
null_loop :: s -> m Bool
null_loop s :: s
s = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield _ _ -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Skip s' :: s
s' -> s -> m Bool
null_loop s
s'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
empty :: Monad m => Stream m a
{-# INLINE_FUSED empty #-}
empty :: Stream m a
empty = (() -> m (Step () a)) -> () -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (m (Step () a) -> () -> m (Step () a)
forall a b. a -> b -> a
const (Step () a -> m (Step () a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step () a
forall s a. Step s a
Done)) ()
singleton :: Monad m => a -> Stream m a
{-# INLINE_FUSED singleton #-}
singleton :: a -> Stream m a
singleton x :: a
x = (Bool -> m (Step Bool a)) -> Bool -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (Step Bool a -> m (Step Bool a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step Bool a -> m (Step Bool a))
-> (Bool -> Step Bool a) -> Bool -> m (Step Bool a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Step Bool a
step) Bool
True
where
{-# INLINE_INNER step #-}
step :: Bool -> Step Bool a
step True = a -> Bool -> Step Bool a
forall a s. a -> s -> Step s a
Yield a
x Bool
False
step False = Step Bool a
forall s a. Step s a
Done
replicate :: Monad m => Int -> a -> Stream m a
{-# INLINE_FUSED replicate #-}
replicate :: Int -> a -> Stream m a
replicate n :: Int
n x :: a
x = Int -> m a -> Stream m a
forall (m :: * -> *) a. Monad m => Int -> m a -> Stream m a
replicateM Int
n (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x)
replicateM :: Monad m => Int -> m a -> Stream m a
{-# INLINE_FUSED replicateM #-}
replicateM :: Int -> m a -> Stream m a
replicateM n :: Int
n p :: m a
p = (Int -> m (Step Int a)) -> Int -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Int -> m (Step Int a)
step Int
n
where
{-# INLINE_INNER step #-}
step :: Int -> m (Step Int a)
step i :: Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = Step Int a -> m (Step Int a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step Int a
forall s a. Step s a
Done
| Bool
otherwise = do { a
x <- m a
p; Step Int a -> m (Step Int a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step Int a -> m (Step Int a)) -> Step Int a -> m (Step Int a)
forall a b. (a -> b) -> a -> b
$ a -> Int -> Step Int a
forall a s. a -> s -> Step s a
Yield a
x (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1) }
generate :: Monad m => Int -> (Int -> a) -> Stream m a
{-# INLINE generate #-}
generate :: Int -> (Int -> a) -> Stream m a
generate n :: Int
n f :: Int -> a
f = Int -> (Int -> m a) -> Stream m a
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> m a) -> Stream m a
generateM Int
n (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> (Int -> a) -> Int -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a
f)
generateM :: Monad m => Int -> (Int -> m a) -> Stream m a
{-# INLINE_FUSED generateM #-}
generateM :: Int -> (Int -> m a) -> Stream m a
generateM n :: Int
n f :: Int -> m a
f = Int
n Int -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (Int -> m (Step Int a)) -> Int -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Int -> m (Step Int a)
step 0
where
{-# INLINE_INNER step #-}
step :: Int -> m (Step Int a)
step i :: Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n = do
a
x <- Int -> m a
f Int
i
Step Int a -> m (Step Int a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step Int a -> m (Step Int a)) -> Step Int a -> m (Step Int a)
forall a b. (a -> b) -> a -> b
$ a -> Int -> Step Int a
forall a s. a -> s -> Step s a
Yield a
x (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
| Bool
otherwise = Step Int a -> m (Step Int a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step Int a
forall s a. Step s a
Done
cons :: Monad m => a -> Stream m a -> Stream m a
{-# INLINE cons #-}
cons :: a -> Stream m a -> Stream m a
cons x :: a
x s :: Stream m a
s = a -> Stream m a
forall (m :: * -> *) a. Monad m => a -> Stream m a
singleton a
x Stream m a -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
Stream m a -> Stream m a -> Stream m a
++ Stream m a
s
snoc :: Monad m => Stream m a -> a -> Stream m a
{-# INLINE snoc #-}
snoc :: Stream m a -> a -> Stream m a
snoc s :: Stream m a
s x :: a
x = Stream m a
s Stream m a -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
Stream m a -> Stream m a -> Stream m a
++ a -> Stream m a
forall (m :: * -> *) a. Monad m => a -> Stream m a
singleton a
x
infixr 5 ++
(++) :: Monad m => Stream m a -> Stream m a -> Stream m a
{-# INLINE_FUSED (++) #-}
Stream stepa :: s -> m (Step s a)
stepa ta :: s
ta ++ :: Stream m a -> Stream m a -> Stream m a
++ Stream stepb :: s -> m (Step s a)
stepb tb :: s
tb = (Either s s -> m (Step (Either s s) a)) -> Either s s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Either s s -> m (Step (Either s s) a)
step (s -> Either s s
forall a b. a -> Either a b
Left s
ta)
where
{-# INLINE_INNER step #-}
step :: Either s s -> m (Step (Either s s) a)
step (Left sa :: s
sa) = do
Step s a
r <- s -> m (Step s a)
stepa s
sa
case Step s a
r of
Yield x :: a
x sa' :: s
sa' -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ a -> Either s s -> Step (Either s s) a
forall a s. a -> s -> Step s a
Yield a
x (s -> Either s s
forall a b. a -> Either a b
Left s
sa')
Skip sa' :: s
sa' -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. a -> Either a b
Left s
sa')
Done -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. b -> Either a b
Right s
tb)
step (Right sb :: s
sb) = do
Step s a
r <- s -> m (Step s a)
stepb s
sb
case Step s a
r of
Yield x :: a
x sb' :: s
sb' -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ a -> Either s s -> Step (Either s s) a
forall a s. a -> s -> Step s a
Yield a
x (s -> Either s s
forall a b. b -> Either a b
Right s
sb')
Skip sb' :: s
sb' -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. b -> Either a b
Right s
sb')
Done -> Step (Either s s) a -> m (Step (Either s s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s s) a -> m (Step (Either s s) a))
-> Step (Either s s) a -> m (Step (Either s s) a)
forall a b. (a -> b) -> a -> b
$ Step (Either s s) a
forall s a. Step s a
Done
head :: Monad m => Stream m a -> m a
{-# INLINE_FUSED head #-}
head :: Stream m a -> m a
head (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m a
head_loop SPEC
SPEC s
t
where
head_loop :: SPEC -> s -> m a
head_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x _ -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
Skip s' :: s
s' -> SPEC -> s -> m a
head_loop SPEC
SPEC s
s'
Done -> EMPTY_STREAM "head"
last :: Monad m => Stream m a -> m a
{-# INLINE_FUSED last #-}
last :: Stream m a -> m a
last (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m a
last_loop0 SPEC
SPEC s
t
where
last_loop0 :: SPEC -> s -> m a
last_loop0 !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> SPEC -> a -> s -> m a
last_loop1 SPEC
SPEC a
x s
s'
Skip s' :: s
s' -> SPEC -> s -> m a
last_loop0 SPEC
SPEC s
s'
Done -> EMPTY_STREAM "last"
last_loop1 :: SPEC -> a -> s -> m a
last_loop1 !SPEC
_ x :: a
x s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield y :: a
y s' :: s
s' -> SPEC -> a -> s -> m a
last_loop1 SPEC
SPEC a
y s
s'
Skip s' :: s
s' -> SPEC -> a -> s -> m a
last_loop1 SPEC
SPEC a
x s
s'
Done -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
infixl 9 !!
(!!) :: Monad m => Stream m a -> Int -> m a
{-# INLINE (!!) #-}
Stream step :: s -> m (Step s a)
step t :: s
t !! :: Stream m a -> Int -> m a
!! j :: Int
j | Int
j Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = ERROR "!!" "negative index"
| Bool
otherwise = SPEC -> s -> Int -> m a
index_loop SPEC
SPEC s
t Int
j
where
index_loop :: SPEC -> s -> Int -> m a
index_loop !SPEC
_ s :: s
s i :: Int
i
= Int
i Int -> m a -> m a
forall a b. a -> b -> b
`seq`
do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0 -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
| Bool
otherwise -> SPEC -> s -> Int -> m a
index_loop SPEC
SPEC s
s' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
Skip s' :: s
s' -> SPEC -> s -> Int -> m a
index_loop SPEC
SPEC s
s' Int
i
Done -> EMPTY_STREAM "!!"
infixl 9 !?
(!?) :: Monad m => Stream m a -> Int -> m (Maybe a)
{-# INLINE (!?) #-}
Stream step :: s -> m (Step s a)
step t :: s
t !? :: Stream m a -> Int -> m (Maybe a)
!? j :: Int
j = SPEC -> s -> Int -> m (Maybe a)
index_loop SPEC
SPEC s
t Int
j
where
index_loop :: SPEC -> s -> Int -> m (Maybe a)
index_loop !SPEC
_ s :: s
s i :: Int
i
= Int
i Int -> m (Maybe a) -> m (Maybe a)
forall a b. a -> b -> b
`seq`
do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' | Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0 -> Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
| Bool
otherwise -> SPEC -> s -> Int -> m (Maybe a)
index_loop SPEC
SPEC s
s' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
Skip s' :: s
s' -> SPEC -> s -> Int -> m (Maybe a)
index_loop SPEC
SPEC s
s' Int
i
Done -> Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
slice :: Monad m => Int
-> Int
-> Stream m a
-> Stream m a
{-# INLINE slice #-}
slice :: Int -> Int -> Stream m a -> Stream m a
slice i :: Int
i n :: Int
n s :: Stream m a
s = Int -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => Int -> Stream m a -> Stream m a
take Int
n (Int -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => Int -> Stream m a -> Stream m a
drop Int
i Stream m a
s)
init :: Monad m => Stream m a -> Stream m a
{-# INLINE_FUSED init #-}
init :: Stream m a -> Stream m a
init (Stream step :: s -> m (Step s a)
step t :: s
t) = ((Maybe a, s) -> m (Step (Maybe a, s) a))
-> (Maybe a, s) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (Maybe a, s) -> m (Step (Maybe a, s) a)
step' (Maybe a
forall a. Maybe a
Nothing, s
t)
where
{-# INLINE_INNER step' #-}
step' :: (Maybe a, s) -> m (Step (Maybe a, s) a)
step' (Nothing, s :: s
s) = (Step s a -> Step (Maybe a, s) a)
-> m (Step s a) -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x s' :: s
s' -> (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (a -> Maybe a
forall a. a -> Maybe a
Just a
x, s
s')
Skip s' :: s
s' -> (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (Maybe a
forall a. Maybe a
Nothing, s
s')
Done -> EMPTY_STREAM "init"
) (s -> m (Step s a)
step s
s)
step' (Just x :: a
x, s :: s
s) = (Step s a -> Step (Maybe a, s) a)
-> m (Step s a) -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield y :: a
y s' :: s
s' -> a -> (Maybe a, s) -> Step (Maybe a, s) a
forall a s. a -> s -> Step s a
Yield a
x (a -> Maybe a
forall a. a -> Maybe a
Just a
y, s
s')
Skip s' :: s
s' -> (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (a -> Maybe a
forall a. a -> Maybe a
Just a
x, s
s')
Done -> Step (Maybe a, s) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
tail :: Monad m => Stream m a -> Stream m a
{-# INLINE_FUSED tail #-}
tail :: Stream m a -> Stream m a
tail (Stream step :: s -> m (Step s a)
step t :: s
t) = (Either s s -> m (Step (Either s s) a)) -> Either s s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Either s s -> m (Step (Either s s) a)
step' (s -> Either s s
forall a b. a -> Either a b
Left s
t)
where
{-# INLINE_INNER step' #-}
step' :: Either s s -> m (Step (Either s s) a)
step' (Left s :: s
s) = (Step s a -> Step (Either s s) a)
-> m (Step s a) -> m (Step (Either s s) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield _ s' :: s
s' -> Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. b -> Either a b
Right s
s')
Skip s' :: s
s' -> Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. a -> Either a b
Left s
s')
Done -> EMPTY_STREAM "tail"
) (s -> m (Step s a)
step s
s)
step' (Right s :: s
s) = (Step s a -> Step (Either s s) a)
-> m (Step s a) -> m (Step (Either s s) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x s' :: s
s' -> a -> Either s s -> Step (Either s s) a
forall a s. a -> s -> Step s a
Yield a
x (s -> Either s s
forall a b. b -> Either a b
Right s
s')
Skip s' :: s
s' -> Either s s -> Step (Either s s) a
forall s a. s -> Step s a
Skip (s -> Either s s
forall a b. b -> Either a b
Right s
s')
Done -> Step (Either s s) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
take :: Monad m => Int -> Stream m a -> Stream m a
{-# INLINE_FUSED take #-}
take :: Int -> Stream m a -> Stream m a
take n :: Int
n (Stream step :: s -> m (Step s a)
step t :: s
t) = Int
n Int -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` ((s, Int) -> m (Step (s, Int) a)) -> (s, Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Int) -> m (Step (s, Int) a)
step' (s
t, 0)
where
{-# INLINE_INNER step' #-}
step' :: (s, Int) -> m (Step (s, Int) a)
step' (s :: s
s, i :: Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n = (Step s a -> Step (s, Int) a)
-> m (Step s a) -> m (Step (s, Int) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x s' :: s
s' -> a -> (s, Int) -> Step (s, Int) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
Skip s' :: s
s' -> (s, Int) -> Step (s, Int) a
forall s a. s -> Step s a
Skip (s
s', Int
i)
Done -> Step (s, Int) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
step' (_, _) = Step (s, Int) a -> m (Step (s, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Int) a
forall s a. Step s a
Done
drop :: Monad m => Int -> Stream m a -> Stream m a
{-# INLINE_FUSED drop #-}
drop :: Int -> Stream m a -> Stream m a
drop n :: Int
n (Stream step :: s -> m (Step s a)
step t :: s
t) = ((s, Maybe Int) -> m (Step (s, Maybe Int) a))
-> (s, Maybe Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Maybe Int) -> m (Step (s, Maybe Int) a)
step' (s
t, Int -> Maybe Int
forall a. a -> Maybe a
Just Int
n)
where
{-# INLINE_INNER step' #-}
step' :: (s, Maybe Int) -> m (Step (s, Maybe Int) a)
step' (s :: s
s, Just i :: Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = (Step s a -> Step (s, Maybe Int) a)
-> m (Step s a) -> m (Step (s, Maybe Int) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield _ s' :: s
s' -> (s, Maybe Int) -> Step (s, Maybe Int) a
forall s a. s -> Step s a
Skip (s
s', Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1))
Skip s' :: s
s' -> (s, Maybe Int) -> Step (s, Maybe Int) a
forall s a. s -> Step s a
Skip (s
s', Int -> Maybe Int
forall a. a -> Maybe a
Just Int
i)
Done -> Step (s, Maybe Int) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
| Bool
otherwise = Step (s, Maybe Int) a -> m (Step (s, Maybe Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe Int) a -> m (Step (s, Maybe Int) a))
-> Step (s, Maybe Int) a -> m (Step (s, Maybe Int) a)
forall a b. (a -> b) -> a -> b
$ (s, Maybe Int) -> Step (s, Maybe Int) a
forall s a. s -> Step s a
Skip (s
s, Maybe Int
forall a. Maybe a
Nothing)
step' (s :: s
s, Nothing) = (Step s a -> Step (s, Maybe Int) a)
-> m (Step s a) -> m (Step (s, Maybe Int) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x s' :: s
s' -> a -> (s, Maybe Int) -> Step (s, Maybe Int) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', Maybe Int
forall a. Maybe a
Nothing)
Skip s' :: s
s' -> (s, Maybe Int) -> Step (s, Maybe Int) a
forall s a. s -> Step s a
Skip (s
s', Maybe Int
forall a. Maybe a
Nothing)
Done -> Step (s, Maybe Int) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
instance Monad m => Functor (Stream m) where
{-# INLINE fmap #-}
fmap :: (a -> b) -> Stream m a -> Stream m b
fmap = (a -> b) -> Stream m a -> Stream m b
forall (m :: * -> *) a b.
Monad m =>
(a -> b) -> Stream m a -> Stream m b
map
map :: Monad m => (a -> b) -> Stream m a -> Stream m b
{-# INLINE map #-}
map :: (a -> b) -> Stream m a -> Stream m b
map f :: a -> b
f = (a -> m b) -> Stream m a -> Stream m b
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM (b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> m b) -> (a -> b) -> a -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)
mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
{-# INLINE_FUSED mapM #-}
mapM :: (a -> m b) -> Stream m a -> Stream m b
mapM f :: a -> m b
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (s -> m (Step s b)) -> s -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s b)
step' s
t
where
{-# INLINE_INNER step' #-}
step' :: s -> m (Step s b)
step' s :: s
s = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> (b -> Step s b) -> m b -> m (Step s b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (b -> s -> Step s b
forall a s. a -> s -> Step s a
`Yield` s
s') (a -> m b
f a
x)
Skip s' :: s
s' -> Step s b -> m (Step s b)
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> Step s b
forall s a. s -> Step s a
Skip s
s')
Done -> Step s b -> m (Step s b)
forall (m :: * -> *) a. Monad m => a -> m a
return Step s b
forall s a. Step s a
Done
consume :: Monad m => Stream m a -> m ()
{-# INLINE_FUSED consume #-}
consume :: Stream m a -> m ()
consume (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m ()
consume_loop SPEC
SPEC s
t
where
consume_loop :: SPEC -> s -> m ()
consume_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield _ s' :: s
s' -> SPEC -> s -> m ()
consume_loop SPEC
SPEC s
s'
Skip s' :: s
s' -> SPEC -> s -> m ()
consume_loop SPEC
SPEC s
s'
Done -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
mapM_ :: Monad m => (a -> m b) -> Stream m a -> m ()
{-# INLINE_FUSED mapM_ #-}
mapM_ :: (a -> m b) -> Stream m a -> m ()
mapM_ m :: a -> m b
m = Stream m b -> m ()
forall (m :: * -> *) a. Monad m => Stream m a -> m ()
consume (Stream m b -> m ())
-> (Stream m a -> Stream m b) -> Stream m a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> Stream m a -> Stream m b
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Stream m a -> Stream m b
mapM a -> m b
m
trans :: (Monad m, Monad m')
=> (forall z. m z -> m' z) -> Stream m a -> Stream m' a
{-# INLINE_FUSED trans #-}
trans :: (forall z. m z -> m' z) -> Stream m a -> Stream m' a
trans f :: forall z. m z -> m' z
f (Stream step :: s -> m (Step s a)
step s :: s
s) = (s -> m' (Step s a)) -> s -> Stream m' a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (m (Step s a) -> m' (Step s a)
forall z. m z -> m' z
f (m (Step s a) -> m' (Step s a))
-> (s -> m (Step s a)) -> s -> m' (Step s a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m (Step s a)
step) s
s
unbox :: Monad m => Stream m (Box a) -> Stream m a
{-# INLINE_FUSED unbox #-}
unbox :: Stream m (Box a) -> Stream m a
unbox (Stream step :: s -> m (Step s (Box a))
step t :: s
t) = (s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step' s
t
where
{-# INLINE_INNER step' #-}
step' :: s -> m (Step s a)
step' s :: s
s = do
Step s (Box a)
r <- s -> m (Step s (Box a))
step s
s
case Step s (Box a)
r of
Yield (Box x :: a
x) s' :: s
s' -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ a -> s -> Step s a
forall a s. a -> s -> Step s a
Yield a
x s
s'
Skip s' :: s
s' -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ s -> Step s a
forall s a. s -> Step s a
Skip s
s'
Done -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ Step s a
forall s a. Step s a
Done
indexed :: Monad m => Stream m a -> Stream m (Int,a)
{-# INLINE_FUSED indexed #-}
indexed :: Stream m a -> Stream m (Int, a)
indexed (Stream step :: s -> m (Step s a)
step t :: s
t) = ((s, Int) -> m (Step (s, Int) (Int, a)))
-> (s, Int) -> Stream m (Int, a)
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Int) -> m (Step (s, Int) (Int, a))
step' (s
t,0)
where
{-# INLINE_INNER step' #-}
step' :: (s, Int) -> m (Step (s, Int) (Int, a))
step' (s :: s
s,i :: Int
i) = Int
i Int -> m (Step (s, Int) (Int, a)) -> m (Step (s, Int) (Int, a))
forall a b. a -> b -> b
`seq`
do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a)))
-> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall a b. (a -> b) -> a -> b
$ (Int, a) -> (s, Int) -> Step (s, Int) (Int, a)
forall a s. a -> s -> Step s a
Yield (Int
i,a
x) (s
s', Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
Skip s' :: s
s' -> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a)))
-> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall a b. (a -> b) -> a -> b
$ (s, Int) -> Step (s, Int) (Int, a)
forall s a. s -> Step s a
Skip (s
s', Int
i)
Done -> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Int) (Int, a)
forall s a. Step s a
Done
indexedR :: Monad m => Int -> Stream m a -> Stream m (Int,a)
{-# INLINE_FUSED indexedR #-}
indexedR :: Int -> Stream m a -> Stream m (Int, a)
indexedR m :: Int
m (Stream step :: s -> m (Step s a)
step t :: s
t) = ((s, Int) -> m (Step (s, Int) (Int, a)))
-> (s, Int) -> Stream m (Int, a)
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Int) -> m (Step (s, Int) (Int, a))
step' (s
t,Int
m)
where
{-# INLINE_INNER step' #-}
step' :: (s, Int) -> m (Step (s, Int) (Int, a))
step' (s :: s
s,i :: Int
i) = Int
i Int -> m (Step (s, Int) (Int, a)) -> m (Step (s, Int) (Int, a))
forall a b. a -> b -> b
`seq`
do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> let i' :: Int
i' = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1
in
Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a)))
-> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall a b. (a -> b) -> a -> b
$ (Int, a) -> (s, Int) -> Step (s, Int) (Int, a)
forall a s. a -> s -> Step s a
Yield (Int
i',a
x) (s
s', Int
i')
Skip s' :: s
s' -> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a)))
-> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall a b. (a -> b) -> a -> b
$ (s, Int) -> Step (s, Int) (Int, a)
forall s a. s -> Step s a
Skip (s
s', Int
i)
Done -> Step (s, Int) (Int, a) -> m (Step (s, Int) (Int, a))
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Int) (Int, a)
forall s a. Step s a
Done
zipWithM :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
{-# INLINE_FUSED zipWithM #-}
zipWithM :: (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM f :: a -> b -> m c
f (Stream stepa :: s -> m (Step s a)
stepa ta :: s
ta) (Stream stepb :: s -> m (Step s b)
stepb tb :: s
tb) = ((s, s, Maybe a) -> m (Step (s, s, Maybe a) c))
-> (s, s, Maybe a) -> Stream m c
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, s, Maybe a) -> m (Step (s, s, Maybe a) c)
step (s
ta, s
tb, Maybe a
forall a. Maybe a
Nothing)
where
{-# INLINE_INNER step #-}
step :: (s, s, Maybe a) -> m (Step (s, s, Maybe a) c)
step (sa :: s
sa, sb :: s
sb, Nothing) = (Step s a -> Step (s, s, Maybe a) c)
-> m (Step s a) -> m (Step (s, s, Maybe a) c)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x sa' :: s
sa' -> (s, s, Maybe a) -> Step (s, s, Maybe a) c
forall s a. s -> Step s a
Skip (s
sa', s
sb, a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Skip sa' :: s
sa' -> (s, s, Maybe a) -> Step (s, s, Maybe a) c
forall s a. s -> Step s a
Skip (s
sa', s
sb, Maybe a
forall a. Maybe a
Nothing)
Done -> Step (s, s, Maybe a) c
forall s a. Step s a
Done
) (s -> m (Step s a)
stepa s
sa)
step (sa :: s
sa, sb :: s
sb, Just x :: a
x) = do
Step s b
r <- s -> m (Step s b)
stepb s
sb
case Step s b
r of
Yield y :: b
y sb' :: s
sb' ->
do
c
z <- a -> b -> m c
f a
x b
y
Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c))
-> Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall a b. (a -> b) -> a -> b
$ c -> (s, s, Maybe a) -> Step (s, s, Maybe a) c
forall a s. a -> s -> Step s a
Yield c
z (s
sa, s
sb', Maybe a
forall a. Maybe a
Nothing)
Skip sb' :: s
sb' -> Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c))
-> Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall a b. (a -> b) -> a -> b
$ (s, s, Maybe a) -> Step (s, s, Maybe a) c
forall s a. s -> Step s a
Skip (s
sa, s
sb', a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Done -> Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c))
-> Step (s, s, Maybe a) c -> m (Step (s, s, Maybe a) c)
forall a b. (a -> b) -> a -> b
$ Step (s, s, Maybe a) c
forall s a. Step s a
Done
{-# RULES
"zipWithM xs xs [Vector.Stream]" forall f xs.
zipWithM f xs xs = mapM (\x -> f x x) xs #-}
zipWithM_ :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> m ()
{-# INLINE zipWithM_ #-}
zipWithM_ :: (a -> b -> m c) -> Stream m a -> Stream m b -> m ()
zipWithM_ f :: a -> b -> m c
f sa :: Stream m a
sa sb :: Stream m b
sb = Stream m c -> m ()
forall (m :: * -> *) a. Monad m => Stream m a -> m ()
consume ((a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM a -> b -> m c
f Stream m a
sa Stream m b
sb)
zipWith3M :: Monad m => (a -> b -> c -> m d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d
{-# INLINE_FUSED zipWith3M #-}
zipWith3M :: (a -> b -> c -> m d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
zipWith3M f :: a -> b -> c -> m d
f (Stream stepa :: s -> m (Step s a)
stepa ta :: s
ta)
(Stream stepb :: s -> m (Step s b)
stepb tb :: s
tb)
(Stream stepc :: s -> m (Step s c)
stepc tc :: s
tc) = ((s, s, s, Maybe (a, Maybe b))
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> (s, s, s, Maybe (a, Maybe b)) -> Stream m d
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, s, s, Maybe (a, Maybe b))
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
step (s
ta, s
tb, s
tc, Maybe (a, Maybe b)
forall a. Maybe a
Nothing)
where
{-# INLINE_INNER step #-}
step :: (s, s, s, Maybe (a, Maybe b))
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
step (sa :: s
sa, sb :: s
sb, sc :: s
sc, Nothing) = do
Step s a
r <- s -> m (Step s a)
stepa s
sa
Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall a b. (a -> b) -> a -> b
$ case Step s a
r of
Yield x :: a
x sa' :: s
sa' -> (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. s -> Step s a
Skip (s
sa', s
sb, s
sc, (a, Maybe b) -> Maybe (a, Maybe b)
forall a. a -> Maybe a
Just (a
x, Maybe b
forall a. Maybe a
Nothing))
Skip sa' :: s
sa' -> (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. s -> Step s a
Skip (s
sa', s
sb, s
sc, Maybe (a, Maybe b)
forall a. Maybe a
Nothing)
Done -> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. Step s a
Done
step (sa :: s
sa, sb :: s
sb, sc :: s
sc, Just (x :: a
x, Nothing)) = do
Step s b
r <- s -> m (Step s b)
stepb s
sb
Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall a b. (a -> b) -> a -> b
$ case Step s b
r of
Yield y :: b
y sb' :: s
sb' -> (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. s -> Step s a
Skip (s
sa, s
sb', s
sc, (a, Maybe b) -> Maybe (a, Maybe b)
forall a. a -> Maybe a
Just (a
x, b -> Maybe b
forall a. a -> Maybe a
Just b
y))
Skip sb' :: s
sb' -> (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. s -> Step s a
Skip (s
sa, s
sb', s
sc, (a, Maybe b) -> Maybe (a, Maybe b)
forall a. a -> Maybe a
Just (a
x, Maybe b
forall a. Maybe a
Nothing))
Done -> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. Step s a
Done
step (sa :: s
sa, sb :: s
sb, sc :: s
sc, Just (x :: a
x, Just y :: b
y)) = do
Step s c
r <- s -> m (Step s c)
stepc s
sc
case Step s c
r of
Yield z :: c
z sc' :: s
sc' -> a -> b -> c -> m d
f a
x b
y c
z m d
-> (d -> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\res :: d
res -> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall a b. (a -> b) -> a -> b
$ d
-> (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall a s. a -> s -> Step s a
Yield d
res (s
sa, s
sb, s
sc', Maybe (a, Maybe b)
forall a. Maybe a
Nothing))
Skip sc' :: s
sc' -> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall a b. (a -> b) -> a -> b
$ (s, s, s, Maybe (a, Maybe b))
-> Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. s -> Step s a
Skip (s
sa, s
sb, s
sc', (a, Maybe b) -> Maybe (a, Maybe b)
forall a. a -> Maybe a
Just (a
x, b -> Maybe b
forall a. a -> Maybe a
Just b
y))
Done -> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d))
-> Step (s, s, s, Maybe (a, Maybe b)) d
-> m (Step (s, s, s, Maybe (a, Maybe b)) d)
forall a b. (a -> b) -> a -> b
$ Step (s, s, s, Maybe (a, Maybe b)) d
forall s a. Step s a
Done
zipWith4M :: Monad m => (a -> b -> c -> d -> m e)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e
{-# INLINE zipWith4M #-}
zipWith4M :: (a -> b -> c -> d -> m e)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
zipWith4M f :: a -> b -> c -> d -> m e
f sa :: Stream m a
sa sb :: Stream m b
sb sc :: Stream m c
sc sd :: Stream m d
sd
= ((a, b) -> (c, d) -> m e)
-> Stream m (a, b) -> Stream m (c, d) -> Stream m e
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM (\(a :: a
a,b :: b
b) (c :: c
c,d :: d
d) -> a -> b -> c -> d -> m e
f a
a b
b c
c d
d) (Stream m a -> Stream m b -> Stream m (a, b)
forall (m :: * -> *) a b.
Monad m =>
Stream m a -> Stream m b -> Stream m (a, b)
zip Stream m a
sa Stream m b
sb) (Stream m c -> Stream m d -> Stream m (c, d)
forall (m :: * -> *) a b.
Monad m =>
Stream m a -> Stream m b -> Stream m (a, b)
zip Stream m c
sc Stream m d
sd)
zipWith5M :: Monad m => (a -> b -> c -> d -> e -> m f)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m f
{-# INLINE zipWith5M #-}
zipWith5M :: (a -> b -> c -> d -> e -> m f)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
zipWith5M f :: a -> b -> c -> d -> e -> m f
f sa :: Stream m a
sa sb :: Stream m b
sb sc :: Stream m c
sc sd :: Stream m d
sd se :: Stream m e
se
= ((a, b, c) -> (d, e) -> m f)
-> Stream m (a, b, c) -> Stream m (d, e) -> Stream m f
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM (\(a :: a
a,b :: b
b,c :: c
c) (d :: d
d,e :: e
e) -> a -> b -> c -> d -> e -> m f
f a
a b
b c
c d
d e
e) (Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
forall (m :: * -> *) a b c.
Monad m =>
Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
zip3 Stream m a
sa Stream m b
sb Stream m c
sc) (Stream m d -> Stream m e -> Stream m (d, e)
forall (m :: * -> *) a b.
Monad m =>
Stream m a -> Stream m b -> Stream m (a, b)
zip Stream m d
sd Stream m e
se)
zipWith6M :: Monad m => (a -> b -> c -> d -> e -> f -> m g)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m f -> Stream m g
{-# INLINE zipWith6M #-}
zipWith6M :: (a -> b -> c -> d -> e -> f -> m g)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m g
zipWith6M fn :: a -> b -> c -> d -> e -> f -> m g
fn sa :: Stream m a
sa sb :: Stream m b
sb sc :: Stream m c
sc sd :: Stream m d
sd se :: Stream m e
se sf :: Stream m f
sf
= ((a, b, c) -> (d, e, f) -> m g)
-> Stream m (a, b, c) -> Stream m (d, e, f) -> Stream m g
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM (\(a :: a
a,b :: b
b,c :: c
c) (d :: d
d,e :: e
e,f :: f
f) -> a -> b -> c -> d -> e -> f -> m g
fn a
a b
b c
c d
d e
e f
f) (Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
forall (m :: * -> *) a b c.
Monad m =>
Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
zip3 Stream m a
sa Stream m b
sb Stream m c
sc)
(Stream m d -> Stream m e -> Stream m f -> Stream m (d, e, f)
forall (m :: * -> *) a b c.
Monad m =>
Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
zip3 Stream m d
sd Stream m e
se Stream m f
sf)
zipWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
{-# INLINE zipWith #-}
zipWith :: (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
zipWith f :: a -> b -> c
f = (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
zipWithM (\a :: a
a b :: b
b -> c -> m c
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> c
f a
a b
b))
zipWith3 :: Monad m => (a -> b -> c -> d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
{-# INLINE zipWith3 #-}
zipWith3 :: (a -> b -> c -> d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
zipWith3 f :: a -> b -> c -> d
f = (a -> b -> c -> m d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> m d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
zipWith3M (\a :: a
a b :: b
b c :: c
c -> d -> m d
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> c -> d
f a
a b
b c
c))
zipWith4 :: Monad m => (a -> b -> c -> d -> e)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e
{-# INLINE zipWith4 #-}
zipWith4 :: (a -> b -> c -> d -> e)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
zipWith4 f :: a -> b -> c -> d -> e
f = (a -> b -> c -> d -> m e)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> m e)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
zipWith4M (\a :: a
a b :: b
b c :: c
c d :: d
d -> e -> m e
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> c -> d -> e
f a
a b
b c
c d
d))
zipWith5 :: Monad m => (a -> b -> c -> d -> e -> f)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m f
{-# INLINE zipWith5 #-}
zipWith5 :: (a -> b -> c -> d -> e -> f)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
zipWith5 f :: a -> b -> c -> d -> e -> f
f = (a -> b -> c -> d -> e -> m f)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> m f)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
zipWith5M (\a :: a
a b :: b
b c :: c
c d :: d
d e :: e
e -> f -> m f
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> c -> d -> e -> f
f a
a b
b c
c d
d e
e))
zipWith6 :: Monad m => (a -> b -> c -> d -> e -> f -> g)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m f -> Stream m g
{-# INLINE zipWith6 #-}
zipWith6 :: (a -> b -> c -> d -> e -> f -> g)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m g
zipWith6 fn :: a -> b -> c -> d -> e -> f -> g
fn = (a -> b -> c -> d -> e -> f -> m g)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m g
forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> m g)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m g
zipWith6M (\a :: a
a b :: b
b c :: c
c d :: d
d e :: e
e f :: f
f -> g -> m g
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> c -> d -> e -> f -> g
fn a
a b
b c
c d
d e
e f
f))
zip :: Monad m => Stream m a -> Stream m b -> Stream m (a,b)
{-# INLINE zip #-}
zip :: Stream m a -> Stream m b -> Stream m (a, b)
zip = (a -> b -> (a, b)) -> Stream m a -> Stream m b -> Stream m (a, b)
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
zipWith (,)
zip3 :: Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m (a,b,c)
{-# INLINE zip3 #-}
zip3 :: Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
zip3 = (a -> b -> c -> (a, b, c))
-> Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> d)
-> Stream m a -> Stream m b -> Stream m c -> Stream m d
zipWith3 (,,)
zip4 :: Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m (a,b,c,d)
{-# INLINE zip4 #-}
zip4 :: Stream m a
-> Stream m b -> Stream m c -> Stream m d -> Stream m (a, b, c, d)
zip4 = (a -> b -> c -> d -> (a, b, c, d))
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m (a, b, c, d)
forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> e)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
zipWith4 (,,,)
zip5 :: Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m (a,b,c,d,e)
{-# INLINE zip5 #-}
zip5 :: Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m (a, b, c, d, e)
zip5 = (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m (a, b, c, d, e)
forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> f)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
zipWith5 (,,,,)
zip6 :: Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d
-> Stream m e -> Stream m f -> Stream m (a,b,c,d,e,f)
{-# INLINE zip6 #-}
zip6 :: Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m (a, b, c, d, e, f)
zip6 = (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m (a, b, c, d, e, f)
forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> g)
-> Stream m a
-> Stream m b
-> Stream m c
-> Stream m d
-> Stream m e
-> Stream m f
-> Stream m g
zipWith6 (,,,,,)
eqBy :: (Monad m) => (a -> b -> Bool) -> Stream m a -> Stream m b -> m Bool
{-# INLINE_FUSED eqBy #-}
eqBy :: (a -> b -> Bool) -> Stream m a -> Stream m b -> m Bool
eqBy eq :: a -> b -> Bool
eq (Stream step1 :: s -> m (Step s a)
step1 t1 :: s
t1) (Stream step2 :: s -> m (Step s b)
step2 t2 :: s
t2) = SPEC -> s -> s -> m Bool
eq_loop0 SPEC
SPEC s
t1 s
t2
where
eq_loop0 :: SPEC -> s -> s -> m Bool
eq_loop0 !SPEC
_ s1 :: s
s1 s2 :: s
s2 = do
Step s a
r <- s -> m (Step s a)
step1 s
s1
case Step s a
r of
Yield x :: a
x s1' :: s
s1' -> SPEC -> a -> s -> s -> m Bool
eq_loop1 SPEC
SPEC a
x s
s1' s
s2
Skip s1' :: s
s1' -> SPEC -> s -> s -> m Bool
eq_loop0 SPEC
SPEC s
s1' s
s2
Done -> s -> m Bool
eq_null s
s2
eq_loop1 :: SPEC -> a -> s -> s -> m Bool
eq_loop1 !SPEC
_ x :: a
x s1 :: s
s1 s2 :: s
s2 = do
Step s b
r <- s -> m (Step s b)
step2 s
s2
case Step s b
r of
Yield y :: b
y s2' :: s
s2'
| a -> b -> Bool
eq a
x b
y -> SPEC -> s -> s -> m Bool
eq_loop0 SPEC
SPEC s
s1 s
s2'
| Bool
otherwise -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Skip s2' :: s
s2' -> SPEC -> a -> s -> s -> m Bool
eq_loop1 SPEC
SPEC a
x s
s1 s
s2'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
eq_null :: s -> m Bool
eq_null s2 :: s
s2 = do
Step s b
r <- s -> m (Step s b)
step2 s
s2
case Step s b
r of
Yield _ _ -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Skip s2' :: s
s2' -> s -> m Bool
eq_null s
s2'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
cmpBy :: (Monad m) => (a -> b -> Ordering) -> Stream m a -> Stream m b -> m Ordering
{-# INLINE_FUSED cmpBy #-}
cmpBy :: (a -> b -> Ordering) -> Stream m a -> Stream m b -> m Ordering
cmpBy cmp :: a -> b -> Ordering
cmp (Stream step1 :: s -> m (Step s a)
step1 t1 :: s
t1) (Stream step2 :: s -> m (Step s b)
step2 t2 :: s
t2) = SPEC -> s -> s -> m Ordering
cmp_loop0 SPEC
SPEC s
t1 s
t2
where
cmp_loop0 :: SPEC -> s -> s -> m Ordering
cmp_loop0 !SPEC
_ s1 :: s
s1 s2 :: s
s2 = do
Step s a
r <- s -> m (Step s a)
step1 s
s1
case Step s a
r of
Yield x :: a
x s1' :: s
s1' -> SPEC -> a -> s -> s -> m Ordering
cmp_loop1 SPEC
SPEC a
x s
s1' s
s2
Skip s1' :: s
s1' -> SPEC -> s -> s -> m Ordering
cmp_loop0 SPEC
SPEC s
s1' s
s2
Done -> s -> m Ordering
cmp_null s
s2
cmp_loop1 :: SPEC -> a -> s -> s -> m Ordering
cmp_loop1 !SPEC
_ x :: a
x s1 :: s
s1 s2 :: s
s2 = do
Step s b
r <- s -> m (Step s b)
step2 s
s2
case Step s b
r of
Yield y :: b
y s2' :: s
s2' -> case a
x a -> b -> Ordering
`cmp` b
y of
EQ -> SPEC -> s -> s -> m Ordering
cmp_loop0 SPEC
SPEC s
s1 s
s2'
c :: Ordering
c -> Ordering -> m Ordering
forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
c
Skip s2' :: s
s2' -> SPEC -> a -> s -> s -> m Ordering
cmp_loop1 SPEC
SPEC a
x s
s1 s
s2'
Done -> Ordering -> m Ordering
forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
GT
cmp_null :: s -> m Ordering
cmp_null s2 :: s
s2 = do
Step s b
r <- s -> m (Step s b)
step2 s
s2
case Step s b
r of
Yield _ _ -> Ordering -> m Ordering
forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
LT
Skip s2' :: s
s2' -> s -> m Ordering
cmp_null s
s2'
Done -> Ordering -> m Ordering
forall (m :: * -> *) a. Monad m => a -> m a
return Ordering
EQ
filter :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
{-# INLINE filter #-}
filter :: (a -> Bool) -> Stream m a -> Stream m a
filter f :: a -> Bool
f = (a -> m Bool) -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
filterM (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (a -> Bool) -> a -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
mapMaybe :: Monad m => (a -> Maybe b) -> Stream m a -> Stream m b
{-# INLINE_FUSED mapMaybe #-}
mapMaybe :: (a -> Maybe b) -> Stream m a -> Stream m b
mapMaybe f :: a -> Maybe b
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (s -> m (Step s b)) -> s -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s b)
step' s
t
where
{-# INLINE_INNER step' #-}
step' :: s -> m (Step s b)
step' s :: s
s = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Step s b -> m (Step s b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ case a -> Maybe b
f a
x of
Nothing -> s -> Step s b
forall s a. s -> Step s a
Skip s
s'
Just b' :: b
b' -> b -> s -> Step s b
forall a s. a -> s -> Step s a
Yield b
b' s
s'
Skip s' :: s
s' -> Step s b -> m (Step s b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ s -> Step s b
forall s a. s -> Step s a
Skip s
s'
Done -> Step s b -> m (Step s b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s b -> m (Step s b)) -> Step s b -> m (Step s b)
forall a b. (a -> b) -> a -> b
$ Step s b
forall s a. Step s a
Done
filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
{-# INLINE_FUSED filterM #-}
filterM :: (a -> m Bool) -> Stream m a -> Stream m a
filterM f :: a -> m Bool
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step' s
t
where
{-# INLINE_INNER step' #-}
step' :: s -> m (Step s a)
step' s :: s
s = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Bool
b <- a -> m Bool
f a
x
Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ if Bool
b then a -> s -> Step s a
forall a s. a -> s -> Step s a
Yield a
x s
s'
else s -> Step s a
forall s a. s -> Step s a
Skip s
s'
Skip s' :: s
s' -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ s -> Step s a
forall s a. s -> Step s a
Skip s
s'
Done -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ Step s a
forall s a. Step s a
Done
uniq :: (Eq a, Monad m) => Stream m a -> Stream m a
{-# INLINE_FUSED uniq #-}
uniq :: Stream m a -> Stream m a
uniq (Stream step :: s -> m (Step s a)
step st :: s
st) = ((Maybe a, s) -> m (Step (Maybe a, s) a))
-> (Maybe a, s) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (Maybe a, s) -> m (Step (Maybe a, s) a)
step' (Maybe a
forall a. Maybe a
Nothing,s
st)
where
{-# INLINE_INNER step' #-}
step' :: (Maybe a, s) -> m (Step (Maybe a, s) a)
step' (Nothing, s :: s
s) = do Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a, s) a -> m (Step (Maybe a, s) a))
-> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall a b. (a -> b) -> a -> b
$ a -> (Maybe a, s) -> Step (Maybe a, s) a
forall a s. a -> s -> Step s a
Yield a
x (a -> Maybe a
forall a. a -> Maybe a
Just a
x , s
s')
Skip s' :: s
s' -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a, s) a -> m (Step (Maybe a, s) a))
-> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall a b. (a -> b) -> a -> b
$ (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (Maybe a
forall a. Maybe a
Nothing, s
s')
Done -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (Maybe a, s) a
forall s a. Step s a
Done
step' (Just x0 :: a
x0, s :: s
s) = do Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x0 -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a, s) a -> m (Step (Maybe a, s) a))
-> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall a b. (a -> b) -> a -> b
$ (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (a -> Maybe a
forall a. a -> Maybe a
Just a
x0, s
s')
| Bool
otherwise -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a, s) a -> m (Step (Maybe a, s) a))
-> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall a b. (a -> b) -> a -> b
$ a -> (Maybe a, s) -> Step (Maybe a, s) a
forall a s. a -> s -> Step s a
Yield a
x (a -> Maybe a
forall a. a -> Maybe a
Just a
x , s
s')
Skip s' :: s
s' -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a, s) a -> m (Step (Maybe a, s) a))
-> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall a b. (a -> b) -> a -> b
$ (Maybe a, s) -> Step (Maybe a, s) a
forall s a. s -> Step s a
Skip (a -> Maybe a
forall a. a -> Maybe a
Just a
x0, s
s')
Done -> Step (Maybe a, s) a -> m (Step (Maybe a, s) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (Maybe a, s) a
forall s a. Step s a
Done
takeWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
{-# INLINE takeWhile #-}
takeWhile :: (a -> Bool) -> Stream m a -> Stream m a
takeWhile f :: a -> Bool
f = (a -> m Bool) -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
takeWhileM (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (a -> Bool) -> a -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
{-# INLINE_FUSED takeWhileM #-}
takeWhileM :: (a -> m Bool) -> Stream m a -> Stream m a
takeWhileM f :: a -> m Bool
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step' s
t
where
{-# INLINE_INNER step' #-}
step' :: s -> m (Step s a)
step' s :: s
s = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Bool
b <- a -> m Bool
f a
x
Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ if Bool
b then a -> s -> Step s a
forall a s. a -> s -> Step s a
Yield a
x s
s' else Step s a
forall s a. Step s a
Done
Skip s' :: s
s' -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ s -> Step s a
forall s a. s -> Step s a
Skip s
s'
Done -> Step s a -> m (Step s a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step s a -> m (Step s a)) -> Step s a -> m (Step s a)
forall a b. (a -> b) -> a -> b
$ Step s a
forall s a. Step s a
Done
dropWhile :: Monad m => (a -> Bool) -> Stream m a -> Stream m a
{-# INLINE dropWhile #-}
dropWhile :: (a -> Bool) -> Stream m a -> Stream m a
dropWhile f :: a -> Bool
f = (a -> m Bool) -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> Stream m a
dropWhileM (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (a -> Bool) -> a -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
data DropWhile s a = DropWhile_Drop s | DropWhile_Yield a s | DropWhile_Next s
dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
{-# INLINE_FUSED dropWhileM #-}
dropWhileM :: (a -> m Bool) -> Stream m a -> Stream m a
dropWhileM f :: a -> m Bool
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (DropWhile s a -> m (Step (DropWhile s a) a))
-> DropWhile s a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream DropWhile s a -> m (Step (DropWhile s a) a)
step' (s -> DropWhile s a
forall s a. s -> DropWhile s a
DropWhile_Drop s
t)
where
{-# INLINE_INNER step' #-}
step' :: DropWhile s a -> m (Step (DropWhile s a) a)
step' (DropWhile_Drop s :: s
s)
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Bool
b <- a -> m Bool
f a
x
Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DropWhile s a) a -> m (Step (DropWhile s a) a))
-> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall a b. (a -> b) -> a -> b
$ if Bool
b then DropWhile s a -> Step (DropWhile s a) a
forall s a. s -> Step s a
Skip (s -> DropWhile s a
forall s a. s -> DropWhile s a
DropWhile_Drop s
s')
else DropWhile s a -> Step (DropWhile s a) a
forall s a. s -> Step s a
Skip (a -> s -> DropWhile s a
forall s a. a -> s -> DropWhile s a
DropWhile_Yield a
x s
s')
Skip s' :: s
s' -> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DropWhile s a) a -> m (Step (DropWhile s a) a))
-> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall a b. (a -> b) -> a -> b
$ DropWhile s a -> Step (DropWhile s a) a
forall s a. s -> Step s a
Skip (s -> DropWhile s a
forall s a. s -> DropWhile s a
DropWhile_Drop s
s')
Done -> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DropWhile s a) a -> m (Step (DropWhile s a) a))
-> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall a b. (a -> b) -> a -> b
$ Step (DropWhile s a) a
forall s a. Step s a
Done
step' (DropWhile_Yield x :: a
x s :: s
s) = Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (DropWhile s a) a -> m (Step (DropWhile s a) a))
-> Step (DropWhile s a) a -> m (Step (DropWhile s a) a)
forall a b. (a -> b) -> a -> b
$ a -> DropWhile s a -> Step (DropWhile s a) a
forall a s. a -> s -> Step s a
Yield a
x (s -> DropWhile s a
forall s a. s -> DropWhile s a
DropWhile_Next s
s)
step' (DropWhile_Next s :: s
s)
= (Step s a -> Step (DropWhile s a) a)
-> m (Step s a) -> m (Step (DropWhile s a) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Step s a
r ->
case Step s a
r of
Yield x :: a
x s' :: s
s' -> DropWhile s a -> Step (DropWhile s a) a
forall s a. s -> Step s a
Skip (a -> s -> DropWhile s a
forall s a. a -> s -> DropWhile s a
DropWhile_Yield a
x s
s')
Skip s' :: s
s' -> DropWhile s a -> Step (DropWhile s a) a
forall s a. s -> Step s a
Skip (s -> DropWhile s a
forall s a. s -> DropWhile s a
DropWhile_Next s
s')
Done -> Step (DropWhile s a) a
forall s a. Step s a
Done
) (s -> m (Step s a)
step s
s)
infix 4 `elem`
elem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
{-# INLINE_FUSED elem #-}
elem :: a -> Stream m a -> m Bool
elem x :: a
x (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m Bool
elem_loop SPEC
SPEC s
t
where
elem_loop :: SPEC -> s -> m Bool
elem_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield y :: a
y s' :: s
s' | a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
| Bool
otherwise -> SPEC -> s -> m Bool
elem_loop SPEC
SPEC s
s'
Skip s' :: s
s' -> SPEC -> s -> m Bool
elem_loop SPEC
SPEC s
s'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
infix 4 `notElem`
notElem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
{-# INLINE notElem #-}
notElem :: a -> Stream m a -> m Bool
notElem x :: a
x s :: Stream m a
s = (Bool -> Bool) -> m Bool -> m Bool
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Bool -> Bool
not (a -> Stream m a -> m Bool
forall (m :: * -> *) a.
(Monad m, Eq a) =>
a -> Stream m a -> m Bool
elem a
x Stream m a
s)
find :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe a)
{-# INLINE find #-}
find :: (a -> Bool) -> Stream m a -> m (Maybe a)
find f :: a -> Bool
f = (a -> m Bool) -> Stream m a -> m (Maybe a)
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> m (Maybe a)
findM (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (a -> Bool) -> a -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
findM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe a)
{-# INLINE_FUSED findM #-}
findM :: (a -> m Bool) -> Stream m a -> m (Maybe a)
findM f :: a -> m Bool
f (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m (Maybe a)
find_loop SPEC
SPEC s
t
where
find_loop :: SPEC -> s -> m (Maybe a)
find_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Bool
b <- a -> m Bool
f a
x
if Bool
b then Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> m (Maybe a)) -> Maybe a -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a
forall a. a -> Maybe a
Just a
x
else SPEC -> s -> m (Maybe a)
find_loop SPEC
SPEC s
s'
Skip s' :: s
s' -> SPEC -> s -> m (Maybe a)
find_loop SPEC
SPEC s
s'
Done -> Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
findIndex :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe Int)
{-# INLINE_FUSED findIndex #-}
findIndex :: (a -> Bool) -> Stream m a -> m (Maybe Int)
findIndex f :: a -> Bool
f = (a -> m Bool) -> Stream m a -> m (Maybe Int)
forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> Stream m a -> m (Maybe Int)
findIndexM (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> m Bool) -> (a -> Bool) -> a -> m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
f)
findIndexM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe Int)
{-# INLINE_FUSED findIndexM #-}
findIndexM :: (a -> m Bool) -> Stream m a -> m (Maybe Int)
findIndexM f :: a -> m Bool
f (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> Int -> m (Maybe Int)
findIndex_loop SPEC
SPEC s
t 0
where
findIndex_loop :: SPEC -> s -> Int -> m (Maybe Int)
findIndex_loop !SPEC
_ s :: s
s i :: Int
i
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> do
Bool
b <- a -> m Bool
f a
x
if Bool
b then Maybe Int -> m (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Int -> m (Maybe Int)) -> Maybe Int -> m (Maybe Int)
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int
forall a. a -> Maybe a
Just Int
i
else SPEC -> s -> Int -> m (Maybe Int)
findIndex_loop SPEC
SPEC s
s' (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
Skip s' :: s
s' -> SPEC -> s -> Int -> m (Maybe Int)
findIndex_loop SPEC
SPEC s
s' Int
i
Done -> Maybe Int -> m (Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Int
forall a. Maybe a
Nothing
foldl :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
{-# INLINE foldl #-}
foldl :: (a -> b -> a) -> a -> Stream m b -> m a
foldl f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
foldlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
{-# INLINE_FUSED foldlM #-}
foldlM :: (a -> b -> m a) -> a -> Stream m b -> m a
foldlM m :: a -> b -> m a
m w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = SPEC -> a -> s -> m a
foldlM_loop SPEC
SPEC a
w s
t
where
foldlM_loop :: SPEC -> a -> s -> m a
foldlM_loop !SPEC
_ z :: a
z s :: s
s
= do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield x :: b
x s' :: s
s' -> do { a
z' <- a -> b -> m a
m a
z b
x; SPEC -> a -> s -> m a
foldlM_loop SPEC
SPEC a
z' s
s' }
Skip s' :: s
s' -> SPEC -> a -> s -> m a
foldlM_loop SPEC
SPEC a
z s
s'
Done -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
z
foldM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
{-# INLINE foldM #-}
foldM :: (a -> b -> m a) -> a -> Stream m b -> m a
foldM = (a -> b -> m a) -> a -> Stream m b -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM
foldl1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
{-# INLINE foldl1 #-}
foldl1 :: (a -> a -> a) -> Stream m a -> m a
foldl1 f :: a -> a -> a
f = (a -> a -> m a) -> Stream m a -> m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> m a
foldl1M (\a :: a
a b :: a
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
a a
b))
foldl1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
{-# INLINE_FUSED foldl1M #-}
foldl1M :: (a -> a -> m a) -> Stream m a -> m a
foldl1M f :: a -> a -> m a
f (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m a
foldl1M_loop SPEC
SPEC s
t
where
foldl1M_loop :: SPEC -> s -> m a
foldl1M_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> (a -> a -> m a) -> a -> Stream m a -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM a -> a -> m a
f a
x ((s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step s
s')
Skip s' :: s
s' -> SPEC -> s -> m a
foldl1M_loop SPEC
SPEC s
s'
Done -> EMPTY_STREAM "foldl1M"
fold1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
{-# INLINE fold1M #-}
fold1M :: (a -> a -> m a) -> Stream m a -> m a
fold1M = (a -> a -> m a) -> Stream m a -> m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> m a
foldl1M
foldl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
{-# INLINE foldl' #-}
foldl' :: (a -> b -> a) -> a -> Stream m b -> m a
foldl' f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM' (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
foldlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
{-# INLINE_FUSED foldlM' #-}
foldlM' :: (a -> b -> m a) -> a -> Stream m b -> m a
foldlM' m :: a -> b -> m a
m w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = SPEC -> a -> s -> m a
foldlM'_loop SPEC
SPEC a
w s
t
where
foldlM'_loop :: SPEC -> a -> s -> m a
foldlM'_loop !SPEC
_ z :: a
z s :: s
s
= a
z a -> m a -> m a
forall a b. a -> b -> b
`seq`
do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield x :: b
x s' :: s
s' -> do { a
z' <- a -> b -> m a
m a
z b
x; SPEC -> a -> s -> m a
foldlM'_loop SPEC
SPEC a
z' s
s' }
Skip s' :: s
s' -> SPEC -> a -> s -> m a
foldlM'_loop SPEC
SPEC a
z s
s'
Done -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
z
foldM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
{-# INLINE foldM' #-}
foldM' :: (a -> b -> m a) -> a -> Stream m b -> m a
foldM' = (a -> b -> m a) -> a -> Stream m b -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM'
foldl1' :: Monad m => (a -> a -> a) -> Stream m a -> m a
{-# INLINE foldl1' #-}
foldl1' :: (a -> a -> a) -> Stream m a -> m a
foldl1' f :: a -> a -> a
f = (a -> a -> m a) -> Stream m a -> m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> m a
foldl1M' (\a :: a
a b :: a
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
a a
b))
foldl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> m a
{-# INLINE_FUSED foldl1M' #-}
foldl1M' :: (a -> a -> m a) -> Stream m a -> m a
foldl1M' f :: a -> a -> m a
f (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m a
foldl1M'_loop SPEC
SPEC s
t
where
foldl1M'_loop :: SPEC -> s -> m a
foldl1M'_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> (a -> a -> m a) -> a -> Stream m a -> m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> m a
foldlM' a -> a -> m a
f a
x ((s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step s
s')
Skip s' :: s
s' -> SPEC -> s -> m a
foldl1M'_loop SPEC
SPEC s
s'
Done -> EMPTY_STREAM "foldl1M'"
fold1M' :: Monad m => (a -> a -> m a) -> Stream m a -> m a
{-# INLINE fold1M' #-}
fold1M' :: (a -> a -> m a) -> Stream m a -> m a
fold1M' = (a -> a -> m a) -> Stream m a -> m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> m a
foldl1M'
foldr :: Monad m => (a -> b -> b) -> b -> Stream m a -> m b
{-# INLINE foldr #-}
foldr :: (a -> b -> b) -> b -> Stream m a -> m b
foldr f :: a -> b -> b
f = (a -> b -> m b) -> b -> Stream m a -> m b
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m b) -> b -> Stream m a -> m b
foldrM (\a :: a
a b :: b
b -> b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> b
f a
a b
b))
foldrM :: Monad m => (a -> b -> m b) -> b -> Stream m a -> m b
{-# INLINE_FUSED foldrM #-}
foldrM :: (a -> b -> m b) -> b -> Stream m a -> m b
foldrM f :: a -> b -> m b
f z :: b
z (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m b
foldrM_loop SPEC
SPEC s
t
where
foldrM_loop :: SPEC -> s -> m b
foldrM_loop !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> a -> b -> m b
f a
x (b -> m b) -> m b -> m b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< SPEC -> s -> m b
foldrM_loop SPEC
SPEC s
s'
Skip s' :: s
s' -> SPEC -> s -> m b
foldrM_loop SPEC
SPEC s
s'
Done -> b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
z
foldr1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
{-# INLINE foldr1 #-}
foldr1 :: (a -> a -> a) -> Stream m a -> m a
foldr1 f :: a -> a -> a
f = (a -> a -> m a) -> Stream m a -> m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> m a
foldr1M (\a :: a
a b :: a
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
a a
b))
foldr1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
{-# INLINE_FUSED foldr1M #-}
foldr1M :: (a -> a -> m a) -> Stream m a -> m a
foldr1M f :: a -> a -> m a
f (Stream step :: s -> m (Step s a)
step t :: s
t) = SPEC -> s -> m a
foldr1M_loop0 SPEC
SPEC s
t
where
foldr1M_loop0 :: SPEC -> s -> m a
foldr1M_loop0 !SPEC
_ s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> SPEC -> a -> s -> m a
foldr1M_loop1 SPEC
SPEC a
x s
s'
Skip s' :: s
s' -> SPEC -> s -> m a
foldr1M_loop0 SPEC
SPEC s
s'
Done -> EMPTY_STREAM "foldr1M"
foldr1M_loop1 :: SPEC -> a -> s -> m a
foldr1M_loop1 !SPEC
_ x :: a
x s :: s
s
= do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield y :: a
y s' :: s
s' -> a -> a -> m a
f a
x (a -> m a) -> m a -> m a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< SPEC -> a -> s -> m a
foldr1M_loop1 SPEC
SPEC a
y s
s'
Skip s' :: s
s' -> SPEC -> a -> s -> m a
foldr1M_loop1 SPEC
SPEC a
x s
s'
Done -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
and :: Monad m => Stream m Bool -> m Bool
{-# INLINE_FUSED and #-}
and :: Stream m Bool -> m Bool
and (Stream step :: s -> m (Step s Bool)
step t :: s
t) = SPEC -> s -> m Bool
and_loop SPEC
SPEC s
t
where
and_loop :: SPEC -> s -> m Bool
and_loop !SPEC
_ s :: s
s
= do
Step s Bool
r <- s -> m (Step s Bool)
step s
s
case Step s Bool
r of
Yield False _ -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
Yield True s' :: s
s' -> SPEC -> s -> m Bool
and_loop SPEC
SPEC s
s'
Skip s' :: s
s' -> SPEC -> s -> m Bool
and_loop SPEC
SPEC s
s'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
or :: Monad m => Stream m Bool -> m Bool
{-# INLINE_FUSED or #-}
or :: Stream m Bool -> m Bool
or (Stream step :: s -> m (Step s Bool)
step t :: s
t) = SPEC -> s -> m Bool
or_loop SPEC
SPEC s
t
where
or_loop :: SPEC -> s -> m Bool
or_loop !SPEC
_ s :: s
s
= do
Step s Bool
r <- s -> m (Step s Bool)
step s
s
case Step s Bool
r of
Yield False s' :: s
s' -> SPEC -> s -> m Bool
or_loop SPEC
SPEC s
s'
Yield True _ -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
Skip s' :: s
s' -> SPEC -> s -> m Bool
or_loop SPEC
SPEC s
s'
Done -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
concatMap :: Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
{-# INLINE concatMap #-}
concatMap :: (a -> Stream m b) -> Stream m a -> Stream m b
concatMap f :: a -> Stream m b
f = (a -> m (Stream m b)) -> Stream m a -> Stream m b
forall (m :: * -> *) a b.
Monad m =>
(a -> m (Stream m b)) -> Stream m a -> Stream m b
concatMapM (Stream m b -> m (Stream m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Stream m b -> m (Stream m b))
-> (a -> Stream m b) -> a -> m (Stream m b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Stream m b
f)
concatMapM :: Monad m => (a -> m (Stream m b)) -> Stream m a -> Stream m b
{-# INLINE_FUSED concatMapM #-}
concatMapM :: (a -> m (Stream m b)) -> Stream m a -> Stream m b
concatMapM f :: a -> m (Stream m b)
f (Stream step :: s -> m (Step s a)
step t :: s
t) = (Either s (Stream m b, s) -> m (Step (Either s (Stream m b, s)) b))
-> Either s (Stream m b, s) -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Either s (Stream m b, s) -> m (Step (Either s (Stream m b, s)) b)
concatMap_go (s -> Either s (Stream m b, s)
forall a b. a -> Either a b
Left s
t)
where
concatMap_go :: Either s (Stream m b, s) -> m (Step (Either s (Stream m b, s)) b)
concatMap_go (Left s :: s
s) = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield a :: a
a s' :: s
s' -> do
Stream m b
b_stream <- a -> m (Stream m b)
f a
a
Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b))
-> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (Stream m b, s) -> Step (Either s (Stream m b, s)) b
forall s a. s -> Step s a
Skip ((Stream m b, s) -> Either s (Stream m b, s)
forall a b. b -> Either a b
Right (Stream m b
b_stream, s
s'))
Skip s' :: s
s' -> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b))
-> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (Stream m b, s) -> Step (Either s (Stream m b, s)) b
forall s a. s -> Step s a
Skip (s -> Either s (Stream m b, s)
forall a b. a -> Either a b
Left s
s')
Done -> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (Either s (Stream m b, s)) b
forall s a. Step s a
Done
concatMap_go (Right (Stream inner_step :: s -> m (Step s b)
inner_step inner_s :: s
inner_s, s :: s
s)) = do
Step s b
r <- s -> m (Step s b)
inner_step s
inner_s
case Step s b
r of
Yield b :: b
b inner_s' :: s
inner_s' -> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b))
-> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall a b. (a -> b) -> a -> b
$ b -> Either s (Stream m b, s) -> Step (Either s (Stream m b, s)) b
forall a s. a -> s -> Step s a
Yield b
b ((Stream m b, s) -> Either s (Stream m b, s)
forall a b. b -> Either a b
Right ((s -> m (Step s b)) -> s -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s b)
inner_step s
inner_s', s
s))
Skip inner_s' :: s
inner_s' -> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b))
-> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (Stream m b, s) -> Step (Either s (Stream m b, s)) b
forall s a. s -> Step s a
Skip ((Stream m b, s) -> Either s (Stream m b, s)
forall a b. b -> Either a b
Right ((s -> m (Step s b)) -> s -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s b)
inner_step s
inner_s', s
s))
Done -> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b))
-> Step (Either s (Stream m b, s)) b
-> m (Step (Either s (Stream m b, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (Stream m b, s) -> Step (Either s (Stream m b, s)) b
forall s a. s -> Step s a
Skip (s -> Either s (Stream m b, s)
forall a b. a -> Either a b
Left s
s)
flatten :: Monad m => (a -> m s) -> (s -> m (Step s b)) -> Stream m a -> Stream m b
{-# INLINE_FUSED flatten #-}
flatten :: (a -> m s) -> (s -> m (Step s b)) -> Stream m a -> Stream m b
flatten mk :: a -> m s
mk istep :: s -> m (Step s b)
istep (Stream ostep :: s -> m (Step s a)
ostep u :: s
u) = (Either s (s, s) -> m (Step (Either s (s, s)) b))
-> Either s (s, s) -> Stream m b
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Either s (s, s) -> m (Step (Either s (s, s)) b)
step (s -> Either s (s, s)
forall a b. a -> Either a b
Left s
u)
where
{-# INLINE_INNER step #-}
step :: Either s (s, s) -> m (Step (Either s (s, s)) b)
step (Left t :: s
t) = do
Step s a
r <- s -> m (Step s a)
ostep s
t
case Step s a
r of
Yield a :: a
a t' :: s
t' -> do
s
s <- a -> m s
mk a
a
s
s s -> m (Step (Either s (s, s)) b) -> m (Step (Either s (s, s)) b)
forall a b. a -> b -> b
`seq` Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either s (s, s) -> Step (Either s (s, s)) b
forall s a. s -> Step s a
Skip ((s, s) -> Either s (s, s)
forall a b. b -> Either a b
Right (s
s,s
t')))
Skip t' :: s
t' -> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b))
-> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (s, s) -> Step (Either s (s, s)) b
forall s a. s -> Step s a
Skip (s -> Either s (s, s)
forall a b. a -> Either a b
Left s
t')
Done -> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b))
-> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall a b. (a -> b) -> a -> b
$ Step (Either s (s, s)) b
forall s a. Step s a
Done
step (Right (s :: s
s,t :: s
t)) = do
Step s b
r <- s -> m (Step s b)
istep s
s
case Step s b
r of
Yield x :: b
x s' :: s
s' -> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b))
-> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall a b. (a -> b) -> a -> b
$ b -> Either s (s, s) -> Step (Either s (s, s)) b
forall a s. a -> s -> Step s a
Yield b
x ((s, s) -> Either s (s, s)
forall a b. b -> Either a b
Right (s
s',s
t))
Skip s' :: s
s' -> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b))
-> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (s, s) -> Step (Either s (s, s)) b
forall s a. s -> Step s a
Skip ((s, s) -> Either s (s, s)
forall a b. b -> Either a b
Right (s
s',s
t))
Done -> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b))
-> Step (Either s (s, s)) b -> m (Step (Either s (s, s)) b)
forall a b. (a -> b) -> a -> b
$ Either s (s, s) -> Step (Either s (s, s)) b
forall s a. s -> Step s a
Skip (s -> Either s (s, s)
forall a b. a -> Either a b
Left s
t)
unfoldr :: Monad m => (s -> Maybe (a, s)) -> s -> Stream m a
{-# INLINE_FUSED unfoldr #-}
unfoldr :: (s -> Maybe (a, s)) -> s -> Stream m a
unfoldr f :: s -> Maybe (a, s)
f = (s -> m (Maybe (a, s))) -> s -> Stream m a
forall (m :: * -> *) s a.
Monad m =>
(s -> m (Maybe (a, s))) -> s -> Stream m a
unfoldrM (Maybe (a, s) -> m (Maybe (a, s))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (a, s) -> m (Maybe (a, s)))
-> (s -> Maybe (a, s)) -> s -> m (Maybe (a, s))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe (a, s)
f)
unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Stream m a
{-# INLINE_FUSED unfoldrM #-}
unfoldrM :: (s -> m (Maybe (a, s))) -> s -> Stream m a
unfoldrM f :: s -> m (Maybe (a, s))
f t :: s
t = (s -> m (Step s a)) -> s -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream s -> m (Step s a)
step s
t
where
{-# INLINE_INNER step #-}
step :: s -> m (Step s a)
step s :: s
s = (Maybe (a, s) -> Step s a) -> m (Maybe (a, s)) -> m (Step s a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Maybe (a, s)
r ->
case Maybe (a, s)
r of
Just (x :: a
x, s' :: s
s') -> a -> s -> Step s a
forall a s. a -> s -> Step s a
Yield a
x s
s'
Nothing -> Step s a
forall s a. Step s a
Done
) (s -> m (Maybe (a, s))
f s
s)
unfoldrN :: Monad m => Int -> (s -> Maybe (a, s)) -> s -> Stream m a
{-# INLINE_FUSED unfoldrN #-}
unfoldrN :: Int -> (s -> Maybe (a, s)) -> s -> Stream m a
unfoldrN n :: Int
n f :: s -> Maybe (a, s)
f = Int -> (s -> m (Maybe (a, s))) -> s -> Stream m a
forall (m :: * -> *) s a.
Monad m =>
Int -> (s -> m (Maybe (a, s))) -> s -> Stream m a
unfoldrNM Int
n (Maybe (a, s) -> m (Maybe (a, s))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (a, s) -> m (Maybe (a, s)))
-> (s -> Maybe (a, s)) -> s -> m (Maybe (a, s))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> Maybe (a, s)
f)
unfoldrNM :: Monad m => Int -> (s -> m (Maybe (a, s))) -> s -> Stream m a
{-# INLINE_FUSED unfoldrNM #-}
unfoldrNM :: Int -> (s -> m (Maybe (a, s))) -> s -> Stream m a
unfoldrNM m :: Int
m f :: s -> m (Maybe (a, s))
f t :: s
t = ((s, Int) -> m (Step (s, Int) a)) -> (s, Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Int) -> m (Step (s, Int) a)
step (s
t,Int
m)
where
{-# INLINE_INNER step #-}
step :: (s, Int) -> m (Step (s, Int) a)
step (s :: s
s,n :: Int
n) | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = Step (s, Int) a -> m (Step (s, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Int) a
forall s a. Step s a
Done
| Bool
otherwise = (Maybe (a, s) -> Step (s, Int) a)
-> m (Maybe (a, s)) -> m (Step (s, Int) a)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\r :: Maybe (a, s)
r ->
case Maybe (a, s)
r of
Just (x :: a
x,s' :: s
s') -> a -> (s, Int) -> Step (s, Int) a
forall a s. a -> s -> Step s a
Yield a
x (s
s',Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
Nothing -> Step (s, Int) a
forall s a. Step s a
Done
) (s -> m (Maybe (a, s))
f s
s)
iterateNM :: Monad m => Int -> (a -> m a) -> a -> Stream m a
{-# INLINE_FUSED iterateNM #-}
iterateNM :: Int -> (a -> m a) -> a -> Stream m a
iterateNM n :: Int
n f :: a -> m a
f x0 :: a
x0 = ((a, Int) -> m (Step (a, Int) a)) -> (a, Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (a, Int) -> m (Step (a, Int) a)
step (a
x0,Int
n)
where
{-# INLINE_INNER step #-}
step :: (a, Int) -> m (Step (a, Int) a)
step (x :: a
x,i :: Int
i) | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = Step (a, Int) a -> m (Step (a, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (a, Int) a
forall s a. Step s a
Done
| Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
n = Step (a, Int) a -> m (Step (a, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (a, Int) a -> m (Step (a, Int) a))
-> Step (a, Int) a -> m (Step (a, Int) a)
forall a b. (a -> b) -> a -> b
$ a -> (a, Int) -> Step (a, Int) a
forall a s. a -> s -> Step s a
Yield a
x (a
x,Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
| Bool
otherwise = do a
a <- a -> m a
f a
x
Step (a, Int) a -> m (Step (a, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (a, Int) a -> m (Step (a, Int) a))
-> Step (a, Int) a -> m (Step (a, Int) a)
forall a b. (a -> b) -> a -> b
$ a -> (a, Int) -> Step (a, Int) a
forall a s. a -> s -> Step s a
Yield a
a (a
a,Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
iterateN :: Monad m => Int -> (a -> a) -> a -> Stream m a
{-# INLINE_FUSED iterateN #-}
iterateN :: Int -> (a -> a) -> a -> Stream m a
iterateN n :: Int
n f :: a -> a
f x0 :: a
x0 = Int -> (a -> m a) -> a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m a) -> a -> Stream m a
iterateNM Int
n (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> (a -> a) -> a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f) a
x0
prescanl :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE prescanl #-}
prescanl :: (a -> b -> a) -> a -> Stream m b -> Stream m a
prescanl f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
prescanlM (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
prescanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE_FUSED prescanlM #-}
prescanlM :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
prescanlM f :: a -> b -> m a
f w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = ((s, a) -> m (Step (s, a) a)) -> (s, a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, a) -> m (Step (s, a) a)
step' (s
t,a
w)
where
{-# INLINE_INNER step' #-}
step' :: (s, a) -> m (Step (s, a) a)
step' (s :: s
s,x :: a
x) = do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield y :: b
y s' :: s
s' -> do
a
z <- a -> b -> m a
f a
x b
y
Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ a -> (s, a) -> Step (s, a) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', a
z)
Skip s' :: s
s' -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ (s, a) -> Step (s, a) a
forall s a. s -> Step s a
Skip (s
s', a
x)
Done -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, a) a
forall s a. Step s a
Done
prescanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE prescanl' #-}
prescanl' :: (a -> b -> a) -> a -> Stream m b -> Stream m a
prescanl' f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
prescanlM' (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
prescanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE_FUSED prescanlM' #-}
prescanlM' :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
prescanlM' f :: a -> b -> m a
f w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = ((s, a) -> m (Step (s, a) a)) -> (s, a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, a) -> m (Step (s, a) a)
step' (s
t,a
w)
where
{-# INLINE_INNER step' #-}
step' :: (s, a) -> m (Step (s, a) a)
step' (s :: s
s,x :: a
x) = a
x a -> m (Step (s, a) a) -> m (Step (s, a) a)
forall a b. a -> b -> b
`seq`
do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield y :: b
y s' :: s
s' -> do
a
z <- a -> b -> m a
f a
x b
y
Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ a -> (s, a) -> Step (s, a) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', a
z)
Skip s' :: s
s' -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ (s, a) -> Step (s, a) a
forall s a. s -> Step s a
Skip (s
s', a
x)
Done -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, a) a
forall s a. Step s a
Done
postscanl :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE postscanl #-}
postscanl :: (a -> b -> a) -> a -> Stream m b -> Stream m a
postscanl f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
postscanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE_FUSED postscanlM #-}
postscanlM :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM f :: a -> b -> m a
f w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = ((s, a) -> m (Step (s, a) a)) -> (s, a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, a) -> m (Step (s, a) a)
step' (s
t,a
w)
where
{-# INLINE_INNER step' #-}
step' :: (s, a) -> m (Step (s, a) a)
step' (s :: s
s,x :: a
x) = do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield y :: b
y s' :: s
s' -> do
a
z <- a -> b -> m a
f a
x b
y
Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ a -> (s, a) -> Step (s, a) a
forall a s. a -> s -> Step s a
Yield a
z (s
s',a
z)
Skip s' :: s
s' -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ (s, a) -> Step (s, a) a
forall s a. s -> Step s a
Skip (s
s',a
x)
Done -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, a) a
forall s a. Step s a
Done
postscanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE postscanl' #-}
postscanl' :: (a -> b -> a) -> a -> Stream m b -> Stream m a
postscanl' f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM' (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
postscanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE_FUSED postscanlM' #-}
postscanlM' :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM' f :: a -> b -> m a
f w :: a
w (Stream step :: s -> m (Step s b)
step t :: s
t) = a
w a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` ((s, a) -> m (Step (s, a) a)) -> (s, a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, a) -> m (Step (s, a) a)
step' (s
t,a
w)
where
{-# INLINE_INNER step' #-}
step' :: (s, a) -> m (Step (s, a) a)
step' (s :: s
s,x :: a
x) = a
x a -> m (Step (s, a) a) -> m (Step (s, a) a)
forall a b. a -> b -> b
`seq`
do
Step s b
r <- s -> m (Step s b)
step s
s
case Step s b
r of
Yield y :: b
y s' :: s
s' -> do
a
z <- a -> b -> m a
f a
x b
y
a
z a -> m (Step (s, a) a) -> m (Step (s, a) a)
forall a b. a -> b -> b
`seq` Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> (s, a) -> Step (s, a) a
forall a s. a -> s -> Step s a
Yield a
z (s
s',a
z))
Skip s' :: s
s' -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, a) a -> m (Step (s, a) a))
-> Step (s, a) a -> m (Step (s, a) a)
forall a b. (a -> b) -> a -> b
$ (s, a) -> Step (s, a) a
forall s a. s -> Step s a
Skip (s
s',a
x)
Done -> Step (s, a) a -> m (Step (s, a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, a) a
forall s a. Step s a
Done
scanl :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE scanl #-}
scanl :: (a -> b -> a) -> a -> Stream m b -> Stream m a
scanl f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
scanlM (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
scanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE scanlM #-}
scanlM :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
scanlM f :: a -> b -> m a
f z :: a
z s :: Stream m b
s = a
z a -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => a -> Stream m a -> Stream m a
`cons` (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM a -> b -> m a
f a
z Stream m b
s
scanl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
{-# INLINE scanl' #-}
scanl' :: (a -> b -> a) -> a -> Stream m b -> Stream m a
scanl' f :: a -> b -> a
f = (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
scanlM' (\a :: a
a b :: b
b -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> b -> a
f a
a b
b))
scanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
{-# INLINE scanlM' #-}
scanlM' :: (a -> b -> m a) -> a -> Stream m b -> Stream m a
scanlM' f :: a -> b -> m a
f z :: a
z s :: Stream m b
s = a
z a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (a
z a -> Stream m a -> Stream m a
forall (m :: * -> *) a. Monad m => a -> Stream m a -> Stream m a
`cons` (a -> b -> m a) -> a -> Stream m b -> Stream m a
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Stream m b -> Stream m a
postscanlM a -> b -> m a
f a
z Stream m b
s)
scanl1 :: Monad m => (a -> a -> a) -> Stream m a -> Stream m a
{-# INLINE scanl1 #-}
scanl1 :: (a -> a -> a) -> Stream m a -> Stream m a
scanl1 f :: a -> a -> a
f = (a -> a -> m a) -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M (\x :: a
x y :: a
y -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
x a
y))
scanl1M :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
{-# INLINE_FUSED scanl1M #-}
scanl1M :: (a -> a -> m a) -> Stream m a -> Stream m a
scanl1M f :: a -> a -> m a
f (Stream step :: s -> m (Step s a)
step t :: s
t) = ((s, Maybe a) -> m (Step (s, Maybe a) a))
-> (s, Maybe a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s
t, Maybe a
forall a. Maybe a
Nothing)
where
{-# INLINE_INNER step' #-}
step' :: (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s :: s
s, Nothing) = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> (s, Maybe a) -> Step (s, Maybe a) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Skip s' :: s
s' -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ (s, Maybe a) -> Step (s, Maybe a) a
forall s a. s -> Step s a
Skip (s
s', Maybe a
forall a. Maybe a
Nothing)
Done -> EMPTY_STREAM "scanl1M"
step' (s :: s
s, Just x :: a
x) = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield y :: a
y s' :: s
s' -> do
a
z <- a -> a -> m a
f a
x a
y
Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> (s, Maybe a) -> Step (s, Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
z)
Skip s' :: s
s' -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ (s, Maybe a) -> Step (s, Maybe a) a
forall s a. s -> Step s a
Skip (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Done -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Maybe a) a
forall s a. Step s a
Done
scanl1' :: Monad m => (a -> a -> a) -> Stream m a -> Stream m a
{-# INLINE scanl1' #-}
scanl1' :: (a -> a -> a) -> Stream m a -> Stream m a
scanl1' f :: a -> a -> a
f = (a -> a -> m a) -> Stream m a -> Stream m a
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Stream m a -> Stream m a
scanl1M' (\x :: a
x y :: a
y -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> a -> a
f a
x a
y))
scanl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
{-# INLINE_FUSED scanl1M' #-}
scanl1M' :: (a -> a -> m a) -> Stream m a -> Stream m a
scanl1M' f :: a -> a -> m a
f (Stream step :: s -> m (Step s a)
step t :: s
t) = ((s, Maybe a) -> m (Step (s, Maybe a) a))
-> (s, Maybe a) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s
t, Maybe a
forall a. Maybe a
Nothing)
where
{-# INLINE_INNER step' #-}
step' :: (s, Maybe a) -> m (Step (s, Maybe a) a)
step' (s :: s
s, Nothing) = do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield x :: a
x s' :: s
s' -> a
x a -> m (Step (s, Maybe a) a) -> m (Step (s, Maybe a) a)
forall a b. a -> b -> b
`seq` Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> (s, Maybe a) -> Step (s, Maybe a) a
forall a s. a -> s -> Step s a
Yield a
x (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
x))
Skip s' :: s
s' -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ (s, Maybe a) -> Step (s, Maybe a) a
forall s a. s -> Step s a
Skip (s
s', Maybe a
forall a. Maybe a
Nothing)
Done -> EMPTY_STREAM "scanl1M"
step' (s :: s
s, Just x :: a
x) = a
x a -> m (Step (s, Maybe a) a) -> m (Step (s, Maybe a) a)
forall a b. a -> b -> b
`seq`
do
Step s a
r <- s -> m (Step s a)
step s
s
case Step s a
r of
Yield y :: a
y s' :: s
s' -> do
a
z <- a -> a -> m a
f a
x a
y
a
z a -> m (Step (s, Maybe a) a) -> m (Step (s, Maybe a) a)
forall a b. a -> b -> b
`seq` Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> (s, Maybe a) -> Step (s, Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
z))
Skip s' :: s
s' -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (s, Maybe a) a -> m (Step (s, Maybe a) a))
-> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall a b. (a -> b) -> a -> b
$ (s, Maybe a) -> Step (s, Maybe a) a
forall s a. s -> Step s a
Skip (s
s', a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Done -> Step (s, Maybe a) a -> m (Step (s, Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step (s, Maybe a) a
forall s a. Step s a
Done
enumFromStepN :: (Num a, Monad m) => a -> a -> Int -> Stream m a
{-# INLINE_FUSED enumFromStepN #-}
enumFromStepN :: a -> a -> Int -> Stream m a
enumFromStepN x :: a
x y :: a
y n :: Int
n = a
x a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
y a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` Int
n Int -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` ((a, Int) -> m (Step (a, Int) a)) -> (a, Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream (a, Int) -> m (Step (a, Int) a)
step (a
x,Int
n)
where
{-# INLINE_INNER step #-}
step :: (a, Int) -> m (Step (a, Int) a)
step (w :: a
w,m :: Int
m) | Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 0 = Step (a, Int) a -> m (Step (a, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (a, Int) a -> m (Step (a, Int) a))
-> Step (a, Int) a -> m (Step (a, Int) a)
forall a b. (a -> b) -> a -> b
$ a -> (a, Int) -> Step (a, Int) a
forall a s. a -> s -> Step s a
Yield a
w (a
wa -> a -> a
forall a. Num a => a -> a -> a
+a
y,Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-1)
| Bool
otherwise = Step (a, Int) a -> m (Step (a, Int) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (a, Int) a -> m (Step (a, Int) a))
-> Step (a, Int) a -> m (Step (a, Int) a)
forall a b. (a -> b) -> a -> b
$ Step (a, Int) a
forall s a. Step s a
Done
enumFromTo :: (Enum a, Monad m) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo #-}
enumFromTo :: a -> a -> Stream m a
enumFromTo x :: a
x y :: a
y = [a] -> Stream m a
forall (m :: * -> *) a. Monad m => [a] -> Stream m a
fromList [a
x .. a
y]
enumFromTo_small :: (Integral a, Monad m) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo_small #-}
enumFromTo_small :: a -> a -> Stream m a
enumFromTo_small x :: a
x y :: a
y = a
x a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
y a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (Maybe a -> m (Step (Maybe a) a)) -> Maybe a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Maybe a -> m (Step (Maybe a) a)
step (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
where
{-# INLINE_INNER step #-}
step :: Maybe a -> m (Step (Maybe a) a)
step Nothing = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
step (Just z :: a
z) | a
z a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z Maybe a
forall a. Maybe a
Nothing
| a
z a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (a -> Maybe a
forall a. a -> Maybe a
Just (a
za -> a -> a
forall a. Num a => a -> a -> a
+1))
| Bool
otherwise = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
{-# RULES
"enumFromTo<Int8> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Int8 -> Int8 -> Stream m Int8
"enumFromTo<Int16> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Int16 -> Int16 -> Stream m Int16
"enumFromTo<Word8> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Word8 -> Word8 -> Stream m Word8
"enumFromTo<Word16> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Word16 -> Word16 -> Stream m Word16 #-}
#if WORD_SIZE_IN_BITS > 32
{-# RULES
"enumFromTo<Int32> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Int32 -> Int32 -> Stream m Int32
"enumFromTo<Word32> [Stream]"
enumFromTo = enumFromTo_small :: Monad m => Word32 -> Word32 -> Stream m Word32 #-}
#endif
enumFromTo_int :: forall m. Monad m => Int -> Int -> Stream m Int
{-# INLINE_FUSED enumFromTo_int #-}
enumFromTo_int :: Int -> Int -> Stream m Int
enumFromTo_int x :: Int
x y :: Int
y = Int
x Int -> Stream m Int -> Stream m Int
forall a b. a -> b -> b
`seq` Int
y Int -> Stream m Int -> Stream m Int
forall a b. a -> b -> b
`seq` (Maybe Int -> m (Step (Maybe Int) Int))
-> Maybe Int -> Stream m Int
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Maybe Int -> m (Step (Maybe Int) Int)
step (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
x)
where
{-# INLINE_INNER step #-}
step :: Maybe Int -> m (Step (Maybe Int) Int)
step Nothing = Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe Int) Int -> m (Step (Maybe Int) Int))
-> Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall a b. (a -> b) -> a -> b
$ Step (Maybe Int) Int
forall s a. Step s a
Done
step (Just z :: Int
z) | Int
z Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
y = Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe Int) Int -> m (Step (Maybe Int) Int))
-> Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int -> Step (Maybe Int) Int
forall a s. a -> s -> Step s a
Yield Int
z Maybe Int
forall a. Maybe a
Nothing
| Int
z Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
y = Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe Int) Int -> m (Step (Maybe Int) Int))
-> Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall a b. (a -> b) -> a -> b
$ Int -> Maybe Int -> Step (Maybe Int) Int
forall a s. a -> s -> Step s a
Yield Int
z (Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
zInt -> Int -> Int
forall a. Num a => a -> a -> a
+1))
| Bool
otherwise = Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe Int) Int -> m (Step (Maybe Int) Int))
-> Step (Maybe Int) Int -> m (Step (Maybe Int) Int)
forall a b. (a -> b) -> a -> b
$ Step (Maybe Int) Int
forall s a. Step s a
Done
enumFromTo_intlike :: (Integral a, Monad m) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo_intlike #-}
enumFromTo_intlike :: a -> a -> Stream m a
enumFromTo_intlike x :: a
x y :: a
y = a
x a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
y a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (Maybe a -> m (Step (Maybe a) a)) -> Maybe a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Maybe a -> m (Step (Maybe a) a)
step (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
where
{-# INLINE_INNER step #-}
step :: Maybe a -> m (Step (Maybe a) a)
step Nothing = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
step (Just z :: a
z) | a
z a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z Maybe a
forall a. Maybe a
Nothing
| a
z a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (a -> Maybe a
forall a. a -> Maybe a
Just (a
za -> a -> a
forall a. Num a => a -> a -> a
+1))
| Bool
otherwise = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
{-# RULES
"enumFromTo<Int> [Stream]"
enumFromTo = enumFromTo_int :: Monad m => Int -> Int -> Stream m Int
#if WORD_SIZE_IN_BITS > 32
"enumFromTo<Int64> [Stream]"
enumFromTo = enumFromTo_intlike :: Monad m => Int64 -> Int64 -> Stream m Int64 #-}
#else
"enumFromTo<Int32> [Stream]"
enumFromTo = enumFromTo_intlike :: Monad m => Int32 -> Int32 -> Stream m Int32 #-}
#endif
enumFromTo_big_word :: (Integral a, Monad m) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo_big_word #-}
enumFromTo_big_word :: a -> a -> Stream m a
enumFromTo_big_word x :: a
x y :: a
y = a
x a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
y a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (Maybe a -> m (Step (Maybe a) a)) -> Maybe a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Maybe a -> m (Step (Maybe a) a)
step (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
where
{-# INLINE_INNER step #-}
step :: Maybe a -> m (Step (Maybe a) a)
step Nothing = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
step (Just z :: a
z) | a
z a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z Maybe a
forall a. Maybe a
Nothing
| a
z a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (a -> Maybe a
forall a. a -> Maybe a
Just (a
za -> a -> a
forall a. Num a => a -> a -> a
+1))
| Bool
otherwise = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
{-# RULES
"enumFromTo<Word> [Stream]"
enumFromTo = enumFromTo_big_word :: Monad m => Word -> Word -> Stream m Word
"enumFromTo<Word64> [Stream]"
enumFromTo = enumFromTo_big_word
:: Monad m => Word64 -> Word64 -> Stream m Word64
#if WORD_SIZE_IN_BITS == 32
"enumFromTo<Word32> [Stream]"
enumFromTo = enumFromTo_big_word
:: Monad m => Word32 -> Word32 -> Stream m Word32
#endif
"enumFromTo<Integer> [Stream]"
enumFromTo = enumFromTo_big_word
:: Monad m => Integer -> Integer -> Stream m Integer #-}
#if WORD_SIZE_IN_BITS > 32
enumFromTo_big_int :: (Integral a, Monad m) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo_big_int #-}
enumFromTo_big_int :: a -> a -> Stream m a
enumFromTo_big_int x :: a
x y :: a
y = a
x a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
y a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (Maybe a -> m (Step (Maybe a) a)) -> Maybe a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Maybe a -> m (Step (Maybe a) a)
step (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
where
{-# INLINE_INNER step #-}
step :: Maybe a -> m (Step (Maybe a) a)
step Nothing = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
step (Just z :: a
z) | a
z a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z Maybe a
forall a. Maybe a
Nothing
| a
z a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
y = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a -> Step (Maybe a) a
forall a s. a -> s -> Step s a
Yield a
z (a -> Maybe a
forall a. a -> Maybe a
Just (a
za -> a -> a
forall a. Num a => a -> a -> a
+1))
| Bool
otherwise = Step (Maybe a) a -> m (Step (Maybe a) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step (Maybe a) a -> m (Step (Maybe a) a))
-> Step (Maybe a) a -> m (Step (Maybe a) a)
forall a b. (a -> b) -> a -> b
$ Step (Maybe a) a
forall s a. Step s a
Done
{-# RULES
"enumFromTo<Int64> [Stream]"
enumFromTo = enumFromTo_big_int :: Monad m => Int64 -> Int64 -> Stream m Int64 #-}
#endif
enumFromTo_char :: Monad m => Char -> Char -> Stream m Char
{-# INLINE_FUSED enumFromTo_char #-}
enumFromTo_char :: Char -> Char -> Stream m Char
enumFromTo_char x :: Char
x y :: Char
y = Char
x Char -> Stream m Char -> Stream m Char
forall a b. a -> b -> b
`seq` Char
y Char -> Stream m Char -> Stream m Char
forall a b. a -> b -> b
`seq` (Int -> m (Step Int Char)) -> Int -> Stream m Char
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream Int -> m (Step Int Char)
step Int
xn
where
xn :: Int
xn = Char -> Int
ord Char
x
yn :: Int
yn = Char -> Int
ord Char
y
{-# INLINE_INNER step #-}
step :: Int -> m (Step Int Char)
step zn :: Int
zn | Int
zn Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
yn = Step Int Char -> m (Step Int Char)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step Int Char -> m (Step Int Char))
-> Step Int Char -> m (Step Int Char)
forall a b. (a -> b) -> a -> b
$ Char -> Int -> Step Int Char
forall a s. a -> s -> Step s a
Yield (Int -> Char
unsafeChr Int
zn) (Int
znInt -> Int -> Int
forall a. Num a => a -> a -> a
+1)
| Bool
otherwise = Step Int Char -> m (Step Int Char)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step Int Char -> m (Step Int Char))
-> Step Int Char -> m (Step Int Char)
forall a b. (a -> b) -> a -> b
$ Step Int Char
forall s a. Step s a
Done
{-# RULES
"enumFromTo<Char> [Stream]"
enumFromTo = enumFromTo_char #-}
enumFromTo_double :: (Monad m, Ord a, RealFrac a) => a -> a -> Stream m a
{-# INLINE_FUSED enumFromTo_double #-}
enumFromTo_double :: a -> a -> Stream m a
enumFromTo_double n :: a
n m :: a
m = a
n a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` a
m a -> Stream m a -> Stream m a
forall a b. a -> b -> b
`seq` (a -> m (Step a a)) -> a -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream a -> m (Step a a)
step a
ini
where
lim :: a
lim = a
m a -> a -> a
forall a. Num a => a -> a -> a
+ 1a -> a -> a
forall a. Fractional a => a -> a -> a
/2
#if MIN_VERSION_base(4,12,0)
ini :: a
ini = 0
step :: a -> m (Step a a)
step x :: a
x | a
x' a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
lim = Step a a -> m (Step a a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step a a -> m (Step a a)) -> Step a a -> m (Step a a)
forall a b. (a -> b) -> a -> b
$ a -> a -> Step a a
forall a s. a -> s -> Step s a
Yield a
x' (a
xa -> a -> a
forall a. Num a => a -> a -> a
+1)
| Bool
otherwise = Step a a -> m (Step a a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Step a a -> m (Step a a)) -> Step a a -> m (Step a a)
forall a b. (a -> b) -> a -> b
$ Step a a
forall s a. Step s a
Done
where
x' :: a
x' = a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
n
#else
ini = n
step x | x <= lim = return $ Yield x (x+1)
| otherwise = return $ Done
#endif
{-# RULES
"enumFromTo<Double> [Stream]"
enumFromTo = enumFromTo_double :: Monad m => Double -> Double -> Stream m Double
"enumFromTo<Float> [Stream]"
enumFromTo = enumFromTo_double :: Monad m => Float -> Float -> Stream m Float #-}
enumFromThenTo :: (Enum a, Monad m) => a -> a -> a -> Stream m a
{-# INLINE_FUSED enumFromThenTo #-}
enumFromThenTo :: a -> a -> a -> Stream m a
enumFromThenTo x :: a
x y :: a
y z :: a
z = [a] -> Stream m a
forall (m :: * -> *) a. Monad m => [a] -> Stream m a
fromList [a
x, a
y .. a
z]
toList :: Monad m => Stream m a -> m [a]
{-# INLINE toList #-}
toList :: Stream m a -> m [a]
toList = (a -> [a] -> [a]) -> [a] -> Stream m a -> m [a]
forall (m :: * -> *) a b.
Monad m =>
(a -> b -> b) -> b -> Stream m a -> m b
foldr (:) []
fromList :: Monad m => [a] -> Stream m a
{-# INLINE fromList #-}
fromList :: [a] -> Stream m a
fromList zs :: [a]
zs = ([a] -> m (Step [a] a)) -> [a] -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream [a] -> m (Step [a] a)
forall (m :: * -> *) a. Monad m => [a] -> m (Step [a] a)
step [a]
zs
where
step :: [a] -> m (Step [a] a)
step (x :: a
x:xs :: [a]
xs) = Step [a] a -> m (Step [a] a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> [a] -> Step [a] a
forall a s. a -> s -> Step s a
Yield a
x [a]
xs)
step [] = Step [a] a -> m (Step [a] a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step [a] a
forall s a. Step s a
Done
fromListN :: Monad m => Int -> [a] -> Stream m a
{-# INLINE_FUSED fromListN #-}
fromListN :: Int -> [a] -> Stream m a
fromListN m :: Int
m zs :: [a]
zs = (([a], Int) -> m (Step ([a], Int) a)) -> ([a], Int) -> Stream m a
forall (m :: * -> *) a s. (s -> m (Step s a)) -> s -> Stream m a
Stream ([a], Int) -> m (Step ([a], Int) a)
forall b (m :: * -> *) a.
(Ord b, Num b, Monad m) =>
([a], b) -> m (Step ([a], b) a)
step ([a]
zs,Int
m)
where
{-# INLINE_INNER step #-}
step :: ([a], b) -> m (Step ([a], b) a)
step (_, n :: b
n) | b
n b -> b -> Bool
forall a. Ord a => a -> a -> Bool
<= 0 = Step ([a], b) a -> m (Step ([a], b) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step ([a], b) a
forall s a. Step s a
Done
step (x :: a
x:xs :: [a]
xs,n :: b
n) = Step ([a], b) a -> m (Step ([a], b) a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> ([a], b) -> Step ([a], b) a
forall a s. a -> s -> Step s a
Yield a
x ([a]
xs,b
nb -> b -> b
forall a. Num a => a -> a -> a
-1))
step ([],_) = Step ([a], b) a -> m (Step ([a], b) a)
forall (m :: * -> *) a. Monad m => a -> m a
return Step ([a], b) a
forall s a. Step s a
Done