Add a "both" utility function for either streams.

This commit is contained in:
Harendra Kumar 2021-07-29 01:27:07 +05:30
parent 064ac664c5
commit 2f5925b421

View File

@ -164,6 +164,7 @@ module Streamly.Internal.Data.Stream.IsStream.Transform
-- Move these to Streamly.Data.Either.Stream?
, lefts
, rights
, both
-- * Concurrent Evaluation
-- ** Concurrent Pipelines
@ -1509,6 +1510,15 @@ lefts = fmap (fromLeft undefined) . filter isLeft
rights :: (IsStream t, Monad m, Functor (t m)) => t m (Either a b) -> t m b
rights = fmap (fromRight undefined) . filter isRight
-- | Remove the either wrapper and flatten both lefts and as well as rights in
-- the output stream.
--
-- /Pre-release/
--
{-# INLINE both #-}
both :: Functor (t m) => t m (Either a a) -> t m a
both = fmap (either id id)
------------------------------------------------------------------------------
-- Concurrent Application
------------------------------------------------------------------------------