Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipes.Prelude: smaller type constraints on fold, length, maximum, minimum, ... #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Pipes/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ True

> Control.Foldl.purely fold :: Monad m => Fold a b -> Producer a m () -> m b
-}
fold :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
fold :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Producer a m r -> m b
fold step begin done p0 = loop p0 begin
where
loop p x = case p of
Expand Down Expand Up @@ -695,12 +695,12 @@ last p0 = do
{-# INLINABLE last #-}

-- | Count the number of elements in a 'Producer'
length :: Monad m => Producer a m () -> m Int
length :: Monad m => Producer a m r -> m Int
length = fold (\n _ -> n + 1) 0 id
{-# INLINABLE length #-}

-- | Find the maximum element of a 'Producer'
maximum :: (Monad m, Ord a) => Producer a m () -> m (Maybe a)
maximum :: (Monad m, Ord a) => Producer a m r -> m (Maybe a)
maximum = fold step Nothing id
where
step x a = Just $ case x of
Expand All @@ -709,7 +709,7 @@ maximum = fold step Nothing id
{-# INLINABLE maximum #-}

-- | Find the minimum element of a 'Producer'
minimum :: (Monad m, Ord a) => Producer a m () -> m (Maybe a)
minimum :: (Monad m, Ord a) => Producer a m r -> m (Maybe a)
minimum = fold step Nothing id
where
step x a = Just $ case x of
Expand All @@ -718,7 +718,7 @@ minimum = fold step Nothing id
{-# INLINABLE minimum #-}

-- | Determine if a 'Producer' is empty
null :: Monad m => Producer a m () -> m Bool
null :: Monad m => Producer a m r -> m Bool
null p = do
x <- next p
return $ case x of
Expand All @@ -727,17 +727,17 @@ null p = do
{-# INLINABLE null #-}

-- | Compute the sum of the elements of a 'Producer'
sum :: (Monad m, Num a) => Producer a m () -> m a
sum :: (Monad m, Num a) => Producer a m r -> m a
sum = fold (+) 0 id
{-# INLINABLE sum #-}

-- | Compute the product of the elements of a 'Producer'
product :: (Monad m, Num a) => Producer a m () -> m a
product :: (Monad m, Num a) => Producer a m r -> m a
product = fold (*) 1 id
{-# INLINABLE product #-}

-- | Convert a pure 'Producer' into a list
toList :: Producer a Identity () -> [a]
toList :: Producer a Identity r -> [a]
toList = loop
where
loop p = case p of
Expand All @@ -754,7 +754,7 @@ toList = loop
immediately as they are generated instead of loading all elements into
memory.
-}
toListM :: Monad m => Producer a m () -> m [a]
toListM :: Monad m => Producer a m r -> m [a]
toListM = loop
where
loop p = case p of
Expand Down