@@ -78,6 +78,11 @@ module Streamly.Internal.Prelude
7878 , foldl1'
7979 , foldlM'
8080
81+ -- ** Concurrent Folds
82+ , foldAsync
83+ , (|$.)
84+ , (|&.)
85+
8186 -- ** Full Folds
8287
8388 -- -- ** To Summary (Full Folds)
@@ -132,12 +137,6 @@ module Streamly.Internal.Prelude
132137 , toStream -- XXX rename to write?
133138 , toStreamRev -- XXX rename to writeRev?
134139
135− -- * Function application
136− , (|$)
137− , (|&)
138− , (|$.)
139− , (|&.)
140−
141140 -- * Transformation
142141 , transform
143142
@@ -172,6 +171,11 @@ module Streamly.Internal.Prelude
172171 -- , lprescanl'
173172 -- , lprescanlM'
174173
174+ -- ** Concurrent Transformation
175+ , applyAsync
176+ , (|$)
177+ , (|&)
178+
175179 -- ** Indexing
176180 , indexed
177181 , indexedR
@@ -1556,10 +1560,19 @@ infixr 0 |$.
15561560infixl 1 |&
15571561infixl 1 |&.
15581562
1559−-- | Parallel function application operator for streams; just like the regular
1560−-- function application operator '$' except that it is concurrent. The
1561−-- following code prints a value every second even though each stage adds a 1
1562−-- second delay.
1563+-- | Parallel transform application operator; applies a stream transformation
1564+-- function @t m a -> t m b@ to a stream @t m a@ concurrently; the input stream
1565+-- is evaluated asynchronously in an independent thread yielding elements to a
1566+-- buffer and the transformation function runs in another thread consuming the
1567+-- input from the buffer. '|$' is just like regular function application
1568+-- operator '$' except that it is concurrent.
1569+--
1570+-- If you read the signature as @(t m a -> t m b) -> (t m a -> t m b)@ you can
1571+-- look at it as a transformation that converts a transform function to a
1572+-- buffered concurrent transform function.
1573+--
1574+-- The following code prints a value every second even though each stage adds a
1575+-- 1 second delay.
15631576--
15641577--
15651578-- @
@@ -1572,11 +1585,20 @@ infixl 1 |&.
15721585--
15731586-- @since 0.3.0
15741587{-# INLINE (|$) #-}
1575−(|$) :: (IsStream t, MonadAsync m) => (t m a -> t m b) -> t m a -> t m b
1588+(|$) :: (IsStream t, MonadAsync m) => (t m a -> t m b) -> (t m a -> t m b)
15761589f |$ x = D.fromStreamD $
15771590 D.applyParallel (D.toStreamD . f . D.fromStreamD) (D.toStreamD x)
15781591-- (|$) = Par.applyParallel
15791592
1593+-- | Same as (|$).
1594+--
1595+-- /Internal/
1596+--
1597+{-# INLINE applyAsync #-}
1598+applyAsync :: (IsStream t, MonadAsync m)
1599+ => (t m a -> t m b) -> (t m a -> t m b)
1600+applyAsync = (|$)
1601+
15801602-- | Parallel reverse function application operator for streams; just like the
15811603-- regular reverse function application operator '&' except that it is
15821604-- concurrent.
@@ -1594,11 +1616,18 @@ f |$ x = D.fromStreamD $
15941616(|&) :: (IsStream t, MonadAsync m) => t m a -> (t m a -> t m b) -> t m b
15951617x |& f = f |$ x
15961618
1597−-- | Parallel function application operator; applies a @run@ or @fold@ function
1598−-- to a stream such that the fold consumer and the stream producer run in
1599−-- parallel. A @run@ or @fold@ function reduces the stream to a value in the
1600−-- underlying monad. The @.@ at the end of the operator is a mnemonic for
1601−-- termination of the stream.
1619+-- | Parallel fold application operator; applies a fold function @t m a -> m b@
1620+-- to a stream @t m a@ concurrently; The the input stream is evaluated
1621+-- asynchronously in an independent thread yielding elements to a buffer and
1622+-- the folding action runs in another thread consuming the input from the
1623+-- buffer.
1624+--
1625+-- If you read the signature as @(t m a -> m b) -> (t m a -> m b)@ you can look
1626+-- at it as a transformation that converts a fold function to a buffered
1627+-- concurrent fold function.
1628+--
1629+-- The @.@ at the end of the operator is a mnemonic for termination of the
1630+-- stream.
16021631--
16031632-- @
16041633-- S.foldlM' (\\_ a -> threadDelay 1000000 >> print a) ()
@@ -1609,10 +1638,18 @@ x |& f = f |$ x
16091638--
16101639-- @since 0.3.0
16111640{-# INLINE (|$.) #-}
1612−(|$.) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> t m a -> m b
1641+(|$.) :: (IsStream t, MonadAsync m) => (t m a -> m b) -> (t m a -> m b)
16131642(|$.) = D.foldParallel
16141643-- (|$.) = Par.foldParallel
16151644
1645+-- | Same as '(|$.)'.
1646+--
1647+-- /Internal/
1648+--
1649+{-# INLINE foldAsync #-}
1650+foldAsync :: (IsStream t, MonadAsync m) => (t m a -> m b) -> (t m a -> m b)
1651+foldAsync = (|$.)
1652+
16161653-- | Parallel reverse function application operator for applying a run or fold
16171654-- functions to a stream. Just like '|$.' except that the operands are reversed.
16181655--