on master help sign in
rename ZipStream to ZipSerial
commit7a9791b4107889ebbe1688e40bad412add132757 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 15 Apr 2018, 13:27 (9 years ago) parent66045e6
3 files changed+40−27
src/Streamly.hs+4−2 src/Streamly/Streams.hs+34−23 src/Streamly/Tutorial.hs+2−2
src/Streamly.hs+4−2
@@ -27,7 +27,7 @@ module Streamly
2727
2828 -- * Zip Style Composition
2929 -- $zipping
30− , ZipStream
30+ , ZipSerial
3131 , ZipAsync
3232
3333 -- * Sum Style Composition
@@ -54,7 +54,7 @@ module Streamly
5454 , runInterleavedT
5555 , runAsyncT
5656 , runParallelT
57− , runZipStream
57+ , runZipSerial
5858 , runZipAsync
5959
6060 -- * Fold Utilities
@@ -73,7 +73,9 @@ module Streamly
7373
7474 -- * Deprecated
7575 , runStreamT
76+ , runZipStream
7677 , StreamT
78+ , ZipStream
7779 )
7880where
7981
src/Streamly/Streams.hs+34−23
@@ -50,7 +50,8 @@ module Streamly.Streams
5050 , InterleavedT
5151 , AsyncT
5252 , ParallelT
53− , ZipStream
53+ , ZipSerial
54+ , ZipStream -- deprecated
5455 , ZipAsync
5556
5657 -- * Type Adapters
@@ -68,7 +69,8 @@ module Streamly.Streams
6869 , runInterleavedT
6970 , runAsyncT
7071 , runParallelT
71− , runZipStream
72+ , runZipSerial
73+ , runZipStream -- deprecated
7274 , runZipAsync
7375
7476 -- * Zipping
@@ -728,10 +730,10 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
728730 yield1 a (Just ra) = merge a ra
729731 (runStream mx) Nothing stp yield1
730732
731−-- | The applicative instance of 'ZipStream' zips a number of streams serially
733+-- | The applicative instance of 'ZipSerial' zips a number of streams serially
732734-- i.e. it produces one element from each stream serially and then zips all
733735-- those elements. Note, for convenience we have used the 'zipping' combinator
734−-- in the following example instead of using a 'ZipStream' type annotation.
736+-- in the following example instead of using a 'ZipSerial' type annotation.
735737--
736738-- @
737739-- main = (toList . 'zipping' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
@@ -745,27 +747,31 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
745747--
746748-- This applicative operation can be seen as the zipping equivalent of
747749-- interleaving with '<=>'.
748−newtype ZipStream m a = ZipStream {getZipStream :: Stream m a}
750+newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
749751 deriving (Semigroup, Monoid)
750752
751−deriving instance MonadAsync m => Alternative (ZipStream m)
753+{-# Deprecated ZipStream "Please use ZipSerial instead." #-}
754+-- | Same as ZipSerial.
755+type ZipStream = ZipSerial
752756
753−instance Monad m => Functor (ZipStream m) where
754− fmap f (ZipStream (Stream m)) = ZipStream $ Stream $ \_ stp yld ->
757+deriving instance MonadAsync m => Alternative (ZipSerial m)
758+
759+instance Monad m => Functor (ZipSerial m) where
760+ fmap f (ZipSerial (Stream m)) = ZipSerial $ Stream $ \_ stp yld ->
755761 let yield a Nothing = yld (f a) Nothing
756762 yield a (Just r) = yld (f a)
757− (Just (getZipStream (fmap f (ZipStream r))))
763+ (Just (getZipSerial (fmap f (ZipSerial r))))
758764 in m Nothing stp yield
759765
760−instance Monad m => Applicative (ZipStream m) where
761− pure = ZipStream . srepeat
766+instance Monad m => Applicative (ZipSerial m) where
767+ pure = ZipSerial . srepeat
762768 (<*>) = zipWith id
763769
764−instance Streaming ZipStream where
765− toStream = getZipStream
766− fromStream = ZipStream
770+instance Streaming ZipSerial where
771+ toStream = getZipSerial
772+ fromStream = ZipSerial
767773
768−instance (Monad m, Num a) => Num (ZipStream m a) where
774+instance (Monad m, Num a) => Num (ZipSerial m a) where
769775 fromInteger n = pure (fromInteger n)
770776
771777 negate = fmap negate
@@ -776,14 +782,14 @@ instance (Monad m, Num a) => Num (ZipStream m a) where
776782 (*) = liftA2 (*)
777783 (-) = liftA2 (-)
778784
779−instance (Monad m, Fractional a) => Fractional (ZipStream m a) where
785+instance (Monad m, Fractional a) => Fractional (ZipSerial m a) where
780786 fromRational n = pure (fromRational n)
781787
782788 recip = fmap recip
783789
784790 (/) = liftA2 (/)
785791
786−instance (Monad m, Floating a) => Floating (ZipStream m a) where
792+instance (Monad m, Floating a) => Floating (ZipSerial m a) where
787793 pi = pure pi
788794
789795 exp = fmap exp
@@ -818,7 +824,7 @@ zipAsyncWith f m1 m2 = fromStream $ Stream $ \_ stp yld -> do
818824 mb <- async m2
819825 (runStream (toStream (zipWith f ma mb))) Nothing stp yld
820826
821−-- | Like 'ZipStream' but zips in parallel, it generates all the elements to
827+-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
822828-- be zipped concurrently.
823829--
824830-- @
@@ -917,8 +923,8 @@ asyncly x = x
917923parallely :: ParallelT m a -> ParallelT m a
918924parallely x = x
919925
920−-- | Interpret an ambiguously typed stream as 'ZipStream'.
921−zipping :: ZipStream m a -> ZipStream m a
926+-- | Interpret an ambiguously typed stream as 'ZipSerial'.
927+zipping :: ZipSerial m a -> ZipSerial m a
922928zipping x = x
923929
924930-- | Interpret an ambiguously typed stream as 'ZipAsync'.
@@ -936,7 +942,7 @@ runSerialT = runStreaming
936942-- | Same as @runSerialT@.
937943{-# Deprecated runStreamT "Please use runSerialT instead." #-}
938944runStreamT :: Monad m => SerialT m a -> m ()
939−runStreamT = runStreaming
945+runStreamT = runSerialT
940946
941947-- | Same as @runStreaming . interleaving@.
942948runInterleavedT :: Monad m => InterleavedT m a -> m ()
@@ -951,8 +957,13 @@ runParallelT :: Monad m => ParallelT m a -> m ()
951957runParallelT = runStreaming
952958
953959-- | Same as @runStreaming . zipping@.
954−runZipStream :: Monad m => ZipStream m a -> m ()
955−runZipStream = runStreaming
960+runZipSerial :: Monad m => ZipSerial m a -> m ()
961+runZipSerial = runStreaming
962+
963+{-# Deprecated runZipStream "Please use runZipSerial instead." #-}
964+-- | Same as ZipSerial.
965+runZipStream :: Monad m => ZipSerial m a -> m ()
966+runZipStream = runZipSerial
956967
957968-- | Same as @runStreaming . zippingAsync@.
958969runZipAsync :: Monad m => ZipAsync m a -> m ()
src/Streamly/Tutorial.hs+2−2
@@ -637,7 +637,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
637637-- $applicative
638638--
639639-- Applicative is precisely the same as the 'ap' operation of 'Monad'. For
640−-- zipping and parallel applicatives separate types 'ZipStream' and 'ZipAsync'
640+-- zipping and parallel applicatives separate types 'ZipSerial' and 'ZipAsync'
641641-- are provided.
642642--
643643-- The following example runs all iterations serially and takes a total 17
@@ -742,7 +742,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
742742
743743-- $serialzip
744744--
745−-- 'ZipStream' zips streams serially:
745+-- 'ZipSerial' zips streams serially:
746746--
747747-- @
748748-- import "Streamly"