{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE QualifiedDo #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_HADDOCK hide #-}
module Streaming.Linear.Internal.Consume
(
stdoutLn,
stdoutLn',
print,
toHandle,
writeFile,
effects,
erase,
drained,
mapM_,
fold,
fold_,
foldM,
foldM_,
all,
all_,
any,
any_,
sum,
sum_,
product,
product_,
head,
head_,
last,
last_,
elem,
elem_,
notElem,
notElem_,
length,
length_,
toList,
toList_,
mconcat,
mconcat_,
minimum,
minimum_,
maximum,
maximum_,
foldrM,
foldrT,
)
where
import qualified Control.Functor.Linear as Control
import qualified Data.Bool.Linear as Linear
import Data.Functor.Identity
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Data.Unrestricted.Linear
import Prelude.Linear (($), (&), (.))
import Streaming.Linear.Internal.Process
import Streaming.Linear.Internal.Type
import qualified System.IO as System
import System.IO.Linear
import System.IO.Resource.Linear
import Prelude
( Bool (..),
Eq (..),
FilePath,
Int,
Maybe (..),
Num (..),
Ord (..),
Show (..),
id,
(&&),
(||),
)
import qualified Prelude as Prelude
stdoutLn :: Stream (Of Text) IO () %1 -> IO ()
stdoutLn :: Stream (Of Text) IO () %1 -> IO ()
stdoutLn Stream (Of Text) IO ()
stream = forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn' Stream (Of Text) IO ()
stream
{-# INLINE stdoutLn #-}
stdoutLn' :: forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn' :: forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn' Stream (Of Text) IO r
stream = Stream (Of Text) IO r %1 -> IO r
loop Stream (Of Text) IO r
stream
where
loop :: Stream (Of Text) IO r %1 -> IO r
loop :: Stream (Of Text) IO r %1 -> IO r
loop Stream (Of Text) IO r
stream =
Stream (Of Text) IO r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect IO (Stream (Of Text) IO r)
ms -> IO (Stream (Of Text) IO r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn'
Step (Text
str :> Stream (Of Text) IO r
stream) -> Control.do
forall a. IO a %1 -> IO a
fromSystemIO forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Text -> IO ()
Text.putStrLn Text
str
forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn' Stream (Of Text) IO r
stream
{-# INLINEABLE stdoutLn' #-}
print :: (Show a) => Stream (Of a) IO r %1 -> IO r
print :: forall a r. Show a => Stream (Of a) IO r %1 -> IO r
print = forall r. Stream (Of Text) IO r %1 -> IO r
stdoutLn' forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map (String -> Text
Text.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Show a => a -> String
Prelude.show)
toHandle :: Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
toHandle :: forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
toHandle Handle
handle Stream (Of Text) RIO r
stream = forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
loop Handle
handle Stream (Of Text) RIO r
stream
where
loop :: Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
loop :: forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
loop Handle
handle Stream (Of Text) RIO r
stream =
Stream (Of Text) RIO r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (r
r, Handle
handle)
Effect RIO (Stream (Of Text) RIO r)
ms -> RIO (Stream (Of Text) RIO r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
toHandle Handle
handle
Step (Text
text :> Stream (Of Text) RIO r
stream') -> Control.do
Handle
handle' <- Handle %1 -> Text -> RIO Handle
hPutStrLn Handle
handle Text
text
forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
toHandle Handle
handle' Stream (Of Text) RIO r
stream'
{-# INLINEABLE toHandle #-}
writeFile :: FilePath -> Stream (Of Text) RIO r %1 -> RIO r
writeFile :: forall r. String -> Stream (Of Text) RIO r %1 -> RIO r
writeFile String
filepath Stream (Of Text) RIO r
stream = Control.do
Handle
handle <- String -> IOMode -> RIO Handle
openFile String
filepath IOMode
System.WriteMode
(r
r, Handle
handle') <- forall r. Handle %1 -> Stream (Of Text) RIO r %1 -> RIO (r, Handle)
toHandle Handle
handle Stream (Of Text) RIO r
stream
Handle %1 -> RIO ()
hClose Handle
handle'
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
effects :: forall a m r. (Control.Monad m) => Stream (Of a) m r %1 -> m r
effects :: forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m r
loop :: Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects
Step (a
_ :> Stream (Of a) m r
stream') -> forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
stream'
{-# INLINEABLE effects #-}
erase :: forall a m r. (Control.Monad m) => Stream (Of a) m r %1 -> Stream Identity m r
erase :: forall a (m :: * -> *) r.
Monad m =>
Stream (Of a) m r %1 -> Stream Identity m r
erase Stream (Of a) m r
stream = Stream (Of a) m r %1 -> Stream Identity m r
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> Stream Identity m r
loop :: Stream (Of a) m r %1 -> Stream Identity m r
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall r (f :: * -> *) (m :: * -> *). r -> Stream f m r
Return r
r
Step (a
_ :> Stream (Of a) m r
stream') -> forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
Step forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a. a -> Identity a
Identity (forall a (m :: * -> *) r.
Monad m =>
Stream (Of a) m r %1 -> Stream Identity m r
erase Stream (Of a) m r
stream')
Effect m (Stream (Of a) m r)
ms -> forall (m :: * -> *) (f :: * -> *) r.
m (Stream f m r) -> Stream f m r
Effect forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= (forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall a (m :: * -> *) r.
Monad m =>
Stream (Of a) m r %1 -> Stream Identity m r
erase)
{-# INLINEABLE erase #-}
drained ::
( Control.Monad m,
Control.Monad (t m),
Control.Functor (t m),
Control.MonadTrans t
) =>
t m (Stream (Of a) m r) %1 ->
t m r
drained :: forall (m :: * -> *) (t :: (* -> *) -> * -> *) a r.
(Monad m, Monad (t m), Functor (t m), MonadTrans t) =>
t m (Stream (Of a) m r) %1 -> t m r
drained = forall (m :: * -> *) a. Monad m => m (m a) %1 -> m a
Control.join forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects)
{-# INLINE drained #-}
mapM_ ::
forall a m b r.
(Consumable b, Control.Monad m) =>
(a -> m b) ->
Stream (Of a) m r %1 ->
m r
mapM_ :: forall a (m :: * -> *) b r.
(Consumable b, Monad m) =>
(a -> m b) -> Stream (Of a) m r %1 -> m r
mapM_ a -> m b
f Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m r
loop :: Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) b r.
(Consumable b, Monad m) =>
(a -> m b) -> Stream (Of a) m r %1 -> m r
mapM_ a -> m b
f
Step (a
a :> Stream (Of a) m r
stream') -> Control.do
b
b <- a -> m b
f a
a
forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a. Consumable a => a %1 -> ()
consume b
b
forall a (m :: * -> *) b r.
(Consumable b, Monad m) =>
(a -> m b) -> Stream (Of a) m r %1 -> m r
mapM_ a -> m b
f Stream (Of a) m r
stream'
{-# INLINEABLE mapM_ #-}
fold ::
forall x a b m r.
(Control.Monad m) =>
(x -> a -> x) ->
x ->
(x -> b) ->
Stream (Of a) m r %1 ->
m (Of b r)
fold :: forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold x -> a -> x
f x
x x -> b
g Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m (Of b r)
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m (Of b r)
loop :: Stream (Of a) m r %1 -> m (Of b r)
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ x -> b
g x
x forall a b. a -> b -> Of a b
:> r
r
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold x -> a -> x
f x
x x -> b
g
Step (a
a :> Stream (Of a) m r
stream') -> forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold x -> a -> x
f (x -> a -> x
f x
x a
a) x -> b
g Stream (Of a) m r
stream'
{-# INLINEABLE fold #-}
fold_ ::
forall x a b m r.
(Control.Monad m, Consumable r) =>
(x -> a -> x) ->
x ->
(x -> b) ->
Stream (Of a) m r %1 ->
m b
fold_ :: forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ x -> a -> x
f x
x x -> b
g Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m b
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m b
loop :: Stream (Of a) m r %1 -> m b
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ x -> b
g x
x
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ x -> a -> x
f x
x x -> b
g
Step (a
a :> Stream (Of a) m r
stream') -> forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ x -> a -> x
f (x -> a -> x
f x
x a
a) x -> b
g Stream (Of a) m r
stream'
{-# INLINEABLE fold_ #-}
foldM ::
forall x a m b r.
(Control.Monad m) =>
(x %1 -> a -> m x) ->
m x ->
(x %1 -> m b) ->
Stream (Of a) m r %1 ->
m (b, r)
foldM :: forall x a (m :: * -> *) b r.
Monad m =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m (b, r)
foldM x %1 -> a -> m x
f m x
mx x %1 -> m b
g Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m (b, r)
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m (b, r)
loop :: Stream (Of a) m r %1 -> m (b, r)
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> m x
mx forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= x %1 -> m b
g forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= (\b
b -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (b
b, r
r))
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall x a (m :: * -> *) b r.
Monad m =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m (b, r)
foldM x %1 -> a -> m x
f m x
mx x %1 -> m b
g
Step (a
a :> Stream (Of a) m r
stream') -> forall x a (m :: * -> *) b r.
Monad m =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m (b, r)
foldM x %1 -> a -> m x
f (m x
mx forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \x
x -> x %1 -> a -> m x
f x
x a
a) x %1 -> m b
g Stream (Of a) m r
stream'
{-# INLINEABLE foldM #-}
foldM_ ::
forall a m x b r.
(Control.Monad m, Consumable r) =>
(x %1 -> a -> m x) ->
m x ->
(x %1 -> m b) ->
Stream (Of a) m r %1 ->
m b
foldM_ :: forall a (m :: * -> *) x b r.
(Monad m, Consumable r) =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m b
foldM_ x %1 -> a -> m x
f m x
mx x %1 -> m b
g Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m b
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m b
loop :: Stream (Of a) m r %1 -> m b
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ m x
mx forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= x %1 -> m b
g
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) x b r.
(Monad m, Consumable r) =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m b
foldM_ x %1 -> a -> m x
f m x
mx x %1 -> m b
g
Step (a
a :> Stream (Of a) m r
stream') -> forall a (m :: * -> *) x b r.
(Monad m, Consumable r) =>
(x %1 -> a -> m x)
-> m x -> (x %1 -> m b) -> Stream (Of a) m r %1 -> m b
foldM_ x %1 -> a -> m x
f (m x
mx forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \x
x -> x %1 -> a -> m x
f x
x a
a) x %1 -> m b
g Stream (Of a) m r
stream'
{-# INLINEABLE foldM_ #-}
all :: (Control.Monad m) => (a -> Bool) -> Stream (Of a) m r %1 -> m (Of Bool r)
all :: forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Stream (Of a) m r %1 -> m (Of Bool r)
all a -> Bool
f Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold Bool -> Bool -> Bool
(&&) Bool
True forall a. a -> a
id (forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map a -> Bool
f Stream (Of a) m r
stream)
{-# INLINEABLE all #-}
all_ :: (Consumable r, Control.Monad m) => (a -> Bool) -> Stream (Of a) m r %1 -> m Bool
all_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
(a -> Bool) -> Stream (Of a) m r %1 -> m Bool
all_ a -> Bool
f Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ Bool -> Bool -> Bool
(&&) Bool
True forall a. a -> a
id (forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map a -> Bool
f Stream (Of a) m r
stream)
{-# INLINEABLE all_ #-}
any :: (Control.Monad m) => (a -> Bool) -> Stream (Of a) m r %1 -> m (Of Bool r)
any :: forall (m :: * -> *) a r.
Monad m =>
(a -> Bool) -> Stream (Of a) m r %1 -> m (Of Bool r)
any a -> Bool
f Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold Bool -> Bool -> Bool
(||) Bool
False forall a. a -> a
id (forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map a -> Bool
f Stream (Of a) m r
stream)
{-# INLINEABLE any #-}
any_ :: (Consumable r, Control.Monad m) => (a -> Bool) -> Stream (Of a) m r %1 -> m Bool
any_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
(a -> Bool) -> Stream (Of a) m r %1 -> m Bool
any_ a -> Bool
f Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ Bool -> Bool -> Bool
(||) Bool
False forall a. a -> a
id (forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map a -> Bool
f Stream (Of a) m r
stream)
{-# INLINEABLE any_ #-}
sum :: (Control.Monad m, Num a) => Stream (Of a) m r %1 -> m (Of a r)
sum :: forall (m :: * -> *) a r.
(Monad m, Num a) =>
Stream (Of a) m r %1 -> m (Of a r)
sum Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold forall a. Num a => a -> a -> a
(+) a
0 forall a. a -> a
id Stream (Of a) m r
stream
{-# INLINE sum #-}
sum_ :: (Control.Monad m, Num a) => Stream (Of a) m () %1 -> m a
sum_ :: forall (m :: * -> *) a.
(Monad m, Num a) =>
Stream (Of a) m () %1 -> m a
sum_ Stream (Of a) m ()
stream = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ forall a. Num a => a -> a -> a
(+) a
0 forall a. a -> a
id Stream (Of a) m ()
stream
{-# INLINE sum_ #-}
product :: (Control.Monad m, Num a) => Stream (Of a) m r %1 -> m (Of a r)
product :: forall (m :: * -> *) a r.
(Monad m, Num a) =>
Stream (Of a) m r %1 -> m (Of a r)
product Stream (Of a) m r
stream = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold forall a. Num a => a -> a -> a
(*) a
1 forall a. a -> a
id Stream (Of a) m r
stream
{-# INLINE product #-}
product_ :: (Control.Monad m, Num a) => Stream (Of a) m () %1 -> m a
product_ :: forall (m :: * -> *) a.
(Monad m, Num a) =>
Stream (Of a) m () %1 -> m a
product_ Stream (Of a) m ()
stream = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ forall a. Num a => a -> a -> a
(*) a
1 forall a. a -> a
id Stream (Of a) m ()
stream
{-# INLINE product_ #-}
head :: (Control.Monad m) => Stream (Of a) m r %1 -> m (Of (Maybe a) r)
head :: forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
head Stream (Of a) m r
str =
Stream (Of a) m r
str forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall a. Maybe a
Nothing forall a b. a -> b -> Of a b
:> r
r)
Effect m (Stream (Of a) m r)
m -> m (Stream (Of a) m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
head
Step (a
a :> Stream (Of a) m r
rest) ->
forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
rest forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall a. a -> Maybe a
Just a
a forall a b. a -> b -> Of a b
:> r
r)
{-# INLINEABLE head #-}
head_ :: (Consumable r, Control.Monad m) => Stream (Of a) m r %1 -> m (Maybe a)
head_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Stream (Of a) m r %1 -> m (Maybe a)
head_ Stream (Of a) m r
str =
Stream (Of a) m r
str forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a. Maybe a
Nothing
Effect m (Stream (Of a) m r)
m -> m (Stream (Of a) m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Stream (Of a) m r %1 -> m (Maybe a)
head_
Step (a
a :> Stream (Of a) m r
rest) ->
forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
rest forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (forall a. a -> Maybe a
Just a
a)
{-# INLINEABLE head_ #-}
last :: (Control.Monad m) => Stream (Of a) m r %1 -> m (Of (Maybe a) r)
last :: forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
last = forall (m :: * -> *) a r.
Monad m =>
Maybe a -> Stream (Of a) m r %1 -> m (Of (Maybe a) r)
loop forall a. Maybe a
Nothing
where
loop ::
(Control.Monad m) =>
Maybe a ->
Stream (Of a) m r %1 ->
m (Of (Maybe a) r)
loop :: forall (m :: * -> *) a r.
Monad m =>
Maybe a -> Stream (Of a) m r %1 -> m (Of (Maybe a) r)
loop Maybe a
m Stream (Of a) m r
s =
Stream (Of a) m r
s forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return (Maybe a
m forall a b. a -> b -> Of a b
:> r
r)
Effect m (Stream (Of a) m r)
m -> m (Stream (Of a) m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
last
Step (a
a :> Stream (Of a) m r
rest) -> forall (m :: * -> *) a r.
Monad m =>
Maybe a -> Stream (Of a) m r %1 -> m (Of (Maybe a) r)
loop (forall a. a -> Maybe a
Just a
a) Stream (Of a) m r
rest
{-# INLINEABLE last #-}
last_ :: (Consumable r, Control.Monad m) => Stream (Of a) m r %1 -> m (Maybe a)
last_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Stream (Of a) m r %1 -> m (Maybe a)
last_ = forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Maybe a -> Stream (Of a) m r %1 -> m (Maybe a)
loop forall a. Maybe a
Nothing
where
loop ::
(Consumable r, Control.Monad m) =>
Maybe a ->
Stream (Of a) m r %1 ->
m (Maybe a)
loop :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Maybe a -> Stream (Of a) m r %1 -> m (Maybe a)
loop Maybe a
m Stream (Of a) m r
s =
Stream (Of a) m r
s forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return Maybe a
m
Effect m (Stream (Of a) m r)
m -> m (Stream (Of a) m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Stream (Of a) m r %1 -> m (Maybe a)
last_
Step (a
a :> Stream (Of a) m r
rest) -> forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Maybe a -> Stream (Of a) m r %1 -> m (Maybe a)
loop (forall a. a -> Maybe a
Just a
a) Stream (Of a) m r
rest
{-# INLINEABLE last_ #-}
elem ::
forall a m r.
(Control.Monad m, Eq a) =>
a ->
Stream (Of a) m r %1 ->
m (Of Bool r)
elem :: forall a (m :: * -> *) r.
(Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m (Of Bool r)
elem a
a Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m (Of Bool r)
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m (Of Bool r)
loop :: Stream (Of a) m r %1 -> m (Of Bool r)
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Bool
False forall a b. a -> b -> Of a b
:> r
r
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) r.
(Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m (Of Bool r)
elem a
a
Step (a
a' :> Stream (Of a) m r
stream') -> case a
a forall a. Eq a => a -> a -> Bool
== a
a' of
Bool
True -> forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
stream' forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= (\r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ Bool
True forall a b. a -> b -> Of a b
:> r
r)
Bool
False -> forall a (m :: * -> *) r.
(Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m (Of Bool r)
elem a
a Stream (Of a) m r
stream'
{-# INLINEABLE elem #-}
infix 4 `elem`
elem_ ::
forall a m r.
(Consumable r, Control.Monad m, Eq a) =>
a ->
Stream (Of a) m r %1 ->
m Bool
elem_ :: forall a (m :: * -> *) r.
(Consumable r, Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m Bool
elem_ a
a Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m Bool
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m Bool
loop :: Stream (Of a) m r %1 -> m Bool
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return Bool
False
Effect m (Stream (Of a) m r)
ms -> m (Stream (Of a) m r)
ms forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) r.
(Consumable r, Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m Bool
elem_ a
a
Step (a
a' :> Stream (Of a) m r
stream') -> case a
a forall a. Eq a => a -> a -> Bool
== a
a' of
Bool
True -> forall a (m :: * -> *) r. Monad m => Stream (Of a) m r %1 -> m r
effects Stream (Of a) m r
stream' forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= \r
r -> forall a b. Consumable a => a %1 -> b %1 -> b
lseq r
r forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return Bool
True
Bool
False -> forall a (m :: * -> *) r.
(Consumable r, Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m Bool
elem_ a
a Stream (Of a) m r
stream'
{-# INLINEABLE elem_ #-}
notElem :: (Control.Monad m, Eq a) => a -> Stream (Of a) m r %1 -> m (Of Bool r)
notElem :: forall (m :: * -> *) a r.
(Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m (Of Bool r)
notElem a
a Stream (Of a) m r
stream = forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap forall r. Of Bool r %1 -> Of Bool r
negate forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *) r.
(Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m (Of Bool r)
elem a
a Stream (Of a) m r
stream
where
negate :: Of Bool r %1 -> Of Bool r
negate :: forall r. Of Bool r %1 -> Of Bool r
negate (Bool
b :> r
r) = Bool -> Bool
Prelude.not Bool
b forall a b. a -> b -> Of a b
:> r
r
{-# INLINE notElem #-}
notElem_ :: (Consumable r, Control.Monad m, Eq a) => a -> Stream (Of a) m r %1 -> m Bool
notElem_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m Bool
notElem_ a
a Stream (Of a) m r
stream = forall (f :: * -> *) a b.
Functor f =>
(a %1 -> b) %1 -> f a %1 -> f b
Control.fmap Bool %1 -> Bool
Linear.not forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ forall a (m :: * -> *) r.
(Consumable r, Monad m, Eq a) =>
a -> Stream (Of a) m r %1 -> m Bool
elem_ a
a Stream (Of a) m r
stream
{-# INLINE notElem_ #-}
length :: (Control.Monad m) => Stream (Of a) m r %1 -> m (Of Int r)
length :: forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of Int r)
length = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold (\Int
n a
_ -> Int
n forall a. Num a => a -> a -> a
+ Int
1) Int
0 forall a. a -> a
id
{-# INLINE length #-}
length_ :: (Consumable r, Control.Monad m) => Stream (Of a) m r %1 -> m Int
length_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m) =>
Stream (Of a) m r %1 -> m Int
length_ = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ (\Int
n a
_ -> Int
n forall a. Num a => a -> a -> a
+ Int
1) Int
0 forall a. a -> a
id
{-# INLINE length_ #-}
toList :: (Control.Monad m) => Stream (Of a) m r %1 -> m (Of [a] r)
toList :: forall (m :: * -> *) a r.
Monad m =>
Stream (Of a) m r %1 -> m (Of [a] r)
toList = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold (\[a] -> [a]
diff a
a [a]
ls -> [a] -> [a]
diff (a
a forall a. a -> [a] -> [a]
: [a]
ls)) forall a. a -> a
id (\[a] -> [a]
diff -> [a] -> [a]
diff [])
{-# INLINE toList #-}
toList_ :: (Control.Monad m) => Stream (Of a) m () %1 -> m [a]
toList_ :: forall (m :: * -> *) a. Monad m => Stream (Of a) m () %1 -> m [a]
toList_ = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ (\[a] -> [a]
diff a
a [a]
ls -> [a] -> [a]
diff (a
a forall a. a -> [a] -> [a]
: [a]
ls)) forall a. a -> a
id (\[a] -> [a]
diff -> [a] -> [a]
diff [])
{-# INLINE toList_ #-}
mconcat :: (Control.Monad m, Prelude.Monoid w) => Stream (Of w) m r %1 -> m (Of w r)
mconcat :: forall (m :: * -> *) w r.
(Monad m, Monoid w) =>
Stream (Of w) m r %1 -> m (Of w r)
mconcat = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold forall a. Semigroup a => a -> a -> a
(Prelude.<>) forall a. Monoid a => a
Prelude.mempty forall a. a -> a
id
{-# INLINE mconcat #-}
mconcat_ ::
(Consumable r, Control.Monad m, Prelude.Monoid w) =>
Stream (Of w) m r %1 ->
m w
mconcat_ :: forall r (m :: * -> *) w.
(Consumable r, Monad m, Monoid w) =>
Stream (Of w) m r %1 -> m w
mconcat_ = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ forall a. Semigroup a => a -> a -> a
(Prelude.<>) forall a. Monoid a => a
Prelude.mempty forall a. a -> a
id
{-# INLINE mconcat_ #-}
minimum :: (Control.Monad m, Ord a) => Stream (Of a) m r %1 -> m (Of (Maybe a) r)
minimum :: forall (m :: * -> *) a r.
(Monad m, Ord a) =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
minimum = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMin forall a. Maybe a
Nothing forall a. a -> a
id forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map forall a. a -> Maybe a
Just
{-# INLINE minimum #-}
minimum_ ::
(Consumable r, Control.Monad m, Ord a) =>
Stream (Of a) m r %1 ->
m (Maybe a)
minimum_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m, Ord a) =>
Stream (Of a) m r %1 -> m (Maybe a)
minimum_ = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMin forall a. Maybe a
Nothing forall a. a -> a
id forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map forall a. a -> Maybe a
Just
{-# INLINE minimum_ #-}
maximum :: (Control.Monad m, Ord a) => Stream (Of a) m r %1 -> m (Of (Maybe a) r)
maximum :: forall (m :: * -> *) a r.
(Monad m, Ord a) =>
Stream (Of a) m r %1 -> m (Of (Maybe a) r)
maximum = forall x a b (m :: * -> *) r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r %1 -> m (Of b r)
fold forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMax forall a. Maybe a
Nothing forall a. a -> a
id forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map forall a. a -> Maybe a
Just
{-# INLINE maximum #-}
maximum_ ::
(Consumable r, Control.Monad m, Ord a) =>
Stream (Of a) m r %1 ->
m (Maybe a)
maximum_ :: forall r (m :: * -> *) a.
(Consumable r, Monad m, Ord a) =>
Stream (Of a) m r %1 -> m (Maybe a)
maximum_ = forall x a b (m :: * -> *) r.
(Monad m, Consumable r) =>
(x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r %1 -> m b
fold_ forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMax forall a. Maybe a
Nothing forall a. a -> a
id forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r %1 -> Stream (Of b) m r
map forall a. a -> Maybe a
Just
{-# INLINE maximum_ #-}
getMin :: (Ord a) => Maybe a -> Maybe a -> Maybe a
getMin :: forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMin = forall a. Ord a => (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
mCompare forall a. Ord a => a -> a -> a
Prelude.min
getMax :: (Ord a) => Maybe a -> Maybe a -> Maybe a
getMax :: forall a. Ord a => Maybe a -> Maybe a -> Maybe a
getMax = forall a. Ord a => (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
mCompare forall a. Ord a => a -> a -> a
Prelude.max
mCompare :: (Ord a) => (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
mCompare :: forall a. Ord a => (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
mCompare a -> a -> a
_ Maybe a
Nothing Maybe a
Nothing = forall a. Maybe a
Nothing
mCompare a -> a -> a
_ (Just a
a) Maybe a
Nothing = forall a. a -> Maybe a
Just a
a
mCompare a -> a -> a
_ Maybe a
Nothing (Just a
a) = forall a. a -> Maybe a
Just a
a
mCompare a -> a -> a
comp (Just a
x) (Just a
y) = forall a. a -> Maybe a
Just forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ a -> a -> a
comp a
x a
y
foldrM ::
forall a m r.
(Control.Monad m) =>
(a -> m r %1 -> m r) ->
Stream (Of a) m r %1 ->
m r
foldrM :: forall a (m :: * -> *) r.
Monad m =>
(a -> m r %1 -> m r) -> Stream (Of a) m r %1 -> m r
foldrM a -> m r %1 -> m r
step Stream (Of a) m r
stream = Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> m r
loop :: Stream (Of a) m r %1 -> m r
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (Of a) m r)
m -> m (Stream (Of a) m r)
m forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (m :: * -> *) r.
Monad m =>
(a -> m r %1 -> m r) -> Stream (Of a) m r %1 -> m r
foldrM a -> m r %1 -> m r
step
Step (a
a :> Stream (Of a) m r
as) -> a -> m r %1 -> m r
step a
a (forall a (m :: * -> *) r.
Monad m =>
(a -> m r %1 -> m r) -> Stream (Of a) m r %1 -> m r
foldrM a -> m r %1 -> m r
step Stream (Of a) m r
as)
{-# INLINEABLE foldrM #-}
foldrT ::
forall a t m r.
(Control.Monad m, Control.MonadTrans t, Control.Monad (t m)) =>
(a -> t m r %1 -> t m r) ->
Stream (Of a) m r %1 ->
t m r
foldrT :: forall a (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(Monad m, MonadTrans t, Monad (t m)) =>
(a -> t m r %1 -> t m r) -> Stream (Of a) m r %1 -> t m r
foldrT a -> t m r %1 -> t m r
step Stream (Of a) m r
stream = Stream (Of a) m r %1 -> t m r
loop Stream (Of a) m r
stream
where
loop :: Stream (Of a) m r %1 -> t m r
loop :: Stream (Of a) m r %1 -> t m r
loop Stream (Of a) m r
stream =
Stream (Of a) m r
stream forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
& \case
Return r
r -> forall (m :: * -> *) a. Monad m => a %1 -> m a
Control.return r
r
Effect m (Stream (Of a) m r)
ms -> (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a %1 -> t m a
Control.lift m (Stream (Of a) m r)
ms) forall (m :: * -> *) a b.
Monad m =>
m a %1 -> (a %1 -> m b) %1 -> m b
Control.>>= forall a (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(Monad m, MonadTrans t, Monad (t m)) =>
(a -> t m r %1 -> t m r) -> Stream (Of a) m r %1 -> t m r
foldrT a -> t m r %1 -> t m r
step
Step (a
a :> Stream (Of a) m r
as) -> a -> t m r %1 -> t m r
step a
a (forall a (t :: (* -> *) -> * -> *) (m :: * -> *) r.
(Monad m, MonadTrans t, Monad (t m)) =>
(a -> t m r %1 -> t m r) -> Stream (Of a) m r %1 -> t m r
foldrT a -> t m r %1 -> t m r
step Stream (Of a) m r
as)
{-# INLINEABLE foldrT #-}