on master help sign in
More consistent naming of operators
commitc77d3fbd6212b8c9407b996ac6d73b5be671a783 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 28 May 2018, 13:24 (8 years ago) parent01f0681
4 files changed+34−19
Changelog.md−2 src/Streamly.hs+3−2 src/Streamly/Streams.hs+29−13 test/Prop.hs+2−2
Changelog.md−2
@@ -4,8 +4,6 @@
44
55* Some prelude functions, to whom concurrency capability has been added, will
66 now require a `MonadAsync` constraint.
7−* Remove the deprecated "<|" operator and reuse it for reverse concurrent fold
8− application operator.
97
108### Bug Fixes
119
src/Streamly.hs+3−2
@@ -87,8 +87,8 @@ module Streamly
8787 -- $application
8888 , (|$)
8989 , (|&)
90− , (<|)
91− , (|>)
90+ , (|$.)
91+ , (|&.)
9292 , mkAsync
9393
9494 -- * Merging Streams
@@ -148,6 +148,7 @@ module Streamly
148148 , zipping
149149 , zippingAsync
150150 , (<=>)
151+ , (<|)
151152 )
152153where
153154
src/Streamly/Streams.hs+29−13
@@ -43,8 +43,8 @@ module Streamly.Streams
4343 , mkAsync
4444 , (|$)
4545 , (|&)
46− , (|>)
47− , (<|)
46+ , (|$.)
47+ , (|&.)
4848
4949 -- * Merging Streams
5050 , serial
@@ -54,6 +54,7 @@ module Streamly.Streams
5454 , wAsync
5555 , parallel
5656 , (<=>) --deprecated
57+ , (<|) --deprecated
5758
5859 -- * IO Streams
5960 , Serial
@@ -330,6 +331,12 @@ runWith :: (IsStream t, MonadAsync m)
330331 => SVarStyle -> (t m a -> m b) -> t m a -> m b
331332runWith style f x = S.runWith style (f . fromStream) (toStream x)
332333
334+infixr 0 |$
335+infixr 0 |$.
336+
337+infixl 1 |&
338+infixl 1 |&.
339+
333340-- | Parallel function application operator for streams; just like the regular
334341-- function application operator '$' except that it is concurrent. The
335342-- following code prints a value every second even though each stage adds a 1
@@ -369,34 +376,35 @@ x |& f = f |$ x
369376-- | Parallel function application operator; applies a @run@ or @fold@ function
370377-- to a stream such that the fold consumer and the stream producer run in
371378-- 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.
373381--
374382-- @
375383-- S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
376−-- <| S.repeatM (threadDelay 1000000 >> return 1)
384+-- |$. S.repeatM (threadDelay 1000000 >> return 1)
377385-- @
378386--
379387-- /Concurrent/
380388--
381389-- @since 0.3.0
382−{-# INLINE (<|) #-}
383−(<|) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> t m a -> m b
384−f <| x = runWith ParallelVar f x
390+{-# INLINE (|$.) #-}
391+(|$.) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> t m a -> m b
392+f |$. x = runWith ParallelVar f x
385393
386394-- | 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.
388396--
389397-- @
390−-- S.repeatM (threadDelay 1000000 >> return 1)
391−-- |> S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
398+-- S.repeatM (threadDelay 1000000 >> return 1)
399+-- |&. S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
392400-- @
393401--
394402-- /Concurrent/
395403--
396404-- @since 0.3.0
397−{-# INLINE (|>) #-}
398−(|>) :: (IsStream t, MonadAsync m) => t m a -> (t m a -> m b) -> m b
399−x |> f = f <| x
405+{-# INLINE (|&.) #-}
406+(|&.) :: (IsStream t, MonadAsync m) => t m a -> (t m a -> m b) -> m b
407+x |&. f = f |$. x
400408
401409------------------------------------------------------------------------------
402410-- CPP macros for common instances
@@ -884,6 +892,14 @@ instance IsStream AsyncT where
884892async :: (IsStream t, MonadAsync m) => t m a -> t m a -> t m a
885893async m1 m2 = fromStream $ S.async (toStream m1) (toStream m2)
886894
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+
887903instance MonadAsync m => Semigroup (AsyncT m a) where
888904 (<>) = async
889905
test/Prop.hs+2−2
@@ -208,7 +208,7 @@ concurrentFoldlApplication n =
208208 -- XXX we should test empty list case as well
209209 let list = [0..n]
210210 stream <- run $ do
211− sourceUnfoldrM1 n |> A.foldlM' (\xs x -> return (x : xs)) []
211+ sourceUnfoldrM1 n |&. A.foldlM' (\xs x -> return (x : xs)) []
212212 equals (==) (reverse stream) list
213213
214214concurrentFoldrApplication :: Word8 -> Property
@@ -217,7 +217,7 @@ concurrentFoldrApplication n =
217217 -- XXX we should test empty list case as well
218218 let list = [0..n]
219219 stream <- run $ do
220− sourceUnfoldrM1 n |> A.foldrM (\x xs -> return (x : xs)) []
220+ sourceUnfoldrM1 n |&. A.foldrM (\x xs -> return (x : xs)) []
221221 equals (==) stream list
222222
223223foldFromList