on master help sign in
More consistent naming of operators
c77d3fbHarendra Kumar
Changelog.md−2
@@ -4,8 +4,6 @@
4
4
5* Some prelude functions, to whom concurrency capability has been added, will
5* Some prelude functions, to whom concurrency capability has been added, will
6 now require a `MonadAsync` constraint.
6 now require a `MonadAsync` constraint.
7−* Remove the deprecated "<|" operator and reuse it for reverse concurrent fold
8− application operator.
9
7
10### Bug Fixes
8### Bug Fixes
11
9
src/Streamly.hs+3−2
@@ -87,8 +87,8 @@ module Streamly
87 -- $application
87 -- $application
88 , (|$)
88 , (|$)
89 , (|&)
89 , (|&)
90− , (<|)
90+ , (|$.)
91− , (|>)
91+ , (|&.)
92 , mkAsync
92 , mkAsync
93
93
94 -- * Merging Streams
94 -- * Merging Streams
@@ -148,6 +148,7 @@ module Streamly
148 , zipping
148 , zipping
149 , zippingAsync
149 , zippingAsync
150 , (<=>)
150 , (<=>)
151+ , (<|)
151 )
152 )
152where
153where
153
154
src/Streamly/Streams.hs+29−13
@@ -43,8 +43,8 @@ module Streamly.Streams
43 , mkAsync
43 , mkAsync
44 , (|$)
44 , (|$)
45 , (|&)
45 , (|&)
46− , (|>)
46+ , (|$.)
47− , (<|)
47+ , (|&.)
48
48
49 -- * Merging Streams
49 -- * Merging Streams
50 , serial
50 , serial
@@ -54,6 +54,7 @@ module Streamly.Streams
54 , wAsync
54 , wAsync
55 , parallel
55 , parallel
56 , (<=>) --deprecated
56 , (<=>) --deprecated
57+ , (<|) --deprecated
57
58
58 -- * IO Streams
59 -- * IO Streams
59 , Serial
60 , Serial
@@ -330,6 +331,12 @@ runWith :: (IsStream t, MonadAsync m)
330 => SVarStyle -> (t m a -> m b) -> t m a -> m b
331 => SVarStyle -> (t m a -> m b) -> t m a -> m b
331runWith style f x = S.runWith style (f . fromStream) (toStream x)
332runWith style f x = S.runWith style (f . fromStream) (toStream x)
332
333
334+infixr 0 |$
335+infixr 0 |$.
336+
337+infixl 1 |&
338+infixl 1 |&.
339+
333-- | Parallel function application operator for streams; just like the regular
340-- | Parallel function application operator for streams; just like the regular
334-- function application operator '$' except that it is concurrent. The
341-- function application operator '$' except that it is concurrent. The
335-- following code prints a value every second even though each stage adds a 1
342-- following code prints a value every second even though each stage adds a 1
@@ -369,34 +376,35 @@ x |& f = f |$ x
369-- | Parallel function application operator; applies a @run@ or @fold@ function
376-- | Parallel function application operator; applies a @run@ or @fold@ function
370-- to a stream such that the fold consumer and the stream producer run in
377-- to a stream such that the fold consumer and the stream producer run in
371-- parallel. A @run@ or @fold@ function reduces the stream to a value in the
378-- parallel. A @run@ or @fold@ function reduces the stream to a value in the
372−-- underlying monad.
379+-- underlying monad. The @.@ at the end of the operator is a mnemonic for
380+-- termination of the stream.
373--
381--
374-- @
382-- @
375-- S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
383-- S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
376−-- <| S.repeatM (threadDelay 1000000 >> return 1)
384+-- |$. S.repeatM (threadDelay 1000000 >> return 1)
377-- @
385-- @
378--
386--
379-- /Concurrent/
387-- /Concurrent/
380--
388--
381-- @since 0.3.0
389-- @since 0.3.0
382−{-# INLINE (<|) #-}
390+{-# INLINE (|$.) #-}
383−(<|) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> t m a -> m b
391+(|$.) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> t m a -> m b
384−f <| x = runWith ParallelVar f x
392+f |$. x = runWith ParallelVar f x
385
393
386-- | Parallel reverse function application operator for applying a run or fold
394-- | Parallel reverse function application operator for applying a run or fold
387−-- functions to a stream. Just like '<|' except that the operands are reversed.
395+-- functions to a stream. Just like '|$.' except that the operands are reversed.
388--
396--
389-- @
397-- @
390−-- S.repeatM (threadDelay 1000000 >> return 1)
398+-- S.repeatM (threadDelay 1000000 >> return 1)
391−-- |> S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
399+-- |&. S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
392-- @
400-- @
393--
401--
394-- /Concurrent/
402-- /Concurrent/
395--
403--
396-- @since 0.3.0
404-- @since 0.3.0
397−{-# INLINE (|>) #-}
405+{-# INLINE (|&.) #-}
398−(|>) :: (IsStream t, MonadAsync m) => t m a -> (t m a -> m b) -> m b
406+(|&.) :: (IsStream t, MonadAsync m) => t m a -> (t m a -> m b) -> m b
399−x |> f = f <| x
407+x |&. f = f |$. x
400
408
401------------------------------------------------------------------------------
409------------------------------------------------------------------------------
402-- CPP macros for common instances
410-- CPP macros for common instances
@@ -884,6 +892,14 @@ instance IsStream AsyncT where
884async :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
892async :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
885async m1 m2 = fromStream $ S.async (toStream m1) (toStream m2)
893async m1 m2 = fromStream $ S.async (toStream m1) (toStream m2)
886
894
895+-- | Same as 'async'.
896+--
897+-- @since 0.1.0
898+{-# DEPRECATED (<|) "Please use 'async' instead." #-}
899+{-# INLINE (<|) #-}
900+(<|) :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
901+(<|) = async
902+
887instance MonadAsync m => Semigroup (AsyncT m a) where
903instance MonadAsync m => Semigroup (AsyncT m a) where
888 (<>) = async
904 (<>) = async
889
905
test/Prop.hs+2−2
@@ -208,7 +208,7 @@ concurrentFoldlApplication n =
208 -- XXX we should test empty list case as well
208 -- XXX we should test empty list case as well
209 let list = [0..n]
209 let list = [0..n]
210 stream <- run $ do
210 stream <- run $ do
211− sourceUnfoldrM1 n |> A.foldlM' (\xs x -> return (x : xs)) []
211+ sourceUnfoldrM1 n |&. A.foldlM' (\xs x -> return (x : xs)) []
212 equals (==) (reverse stream) list
212 equals (==) (reverse stream) list
213
213
214concurrentFoldrApplication :: Word8 -> Property
214concurrentFoldrApplication :: Word8 -> Property
@@ -217,7 +217,7 @@ concurrentFoldrApplication n =
217 -- XXX we should test empty list case as well
217 -- XXX we should test empty list case as well
218 let list = [0..n]
218 let list = [0..n]
219 stream <- run $ do
219 stream <- run $ do
220− sourceUnfoldrM1 n |> A.foldrM (\x xs -> return (x : xs)) []
220+ sourceUnfoldrM1 n |&. A.foldrM (\x xs -> return (x : xs)) []
221 equals (==) stream list
221 equals (==) stream list
222
222
223foldFromList
223foldFromList