on master help sign in
Update the Fold.Prelude module, export concurrent ops
commit0285479816064c35fdfb50de09fc3c70e6fb07ff authorHarendra Kumar <harendra@composewell.com> dateSun 26 Nov 2023, 12:44 (3 years ago) parente6cc89b
1 file changed+31−13
src/Streamly/Data/Fold/Prelude.hs+31−13
src/Streamly/Data/Fold/Prelude.hs+31−13
@@ -6,8 +6,27 @@
66-- Stability : released
77-- Portability : GHC
88--
9+-- All Fold related combinators including the streamly-core
10+-- "Streamly.Data.Fold" module, concurrency, unordered container operations.
11+--
912module Streamly.Data.Fold.Prelude
10− ( module Streamly.Data.Fold
13+ (
14+ -- * "Streamly.Data.Fold"
15+ -- | All "Streamly.Data.Fold" combinators are re-exported via this
16+ -- module. For more pre-release combinators also see
17+ -- "Streamly.Internal.Data.Fold" module.
18+ module Streamly.Data.Fold
19+ -- * Concurrent Operations
20+ -- ** Configuration
21+ , Config
22+ , maxBuffer
23+ , bound
24+ , inspect
25+
26+ -- ** Combinators
27+ , parEval
28+
29+ -- * Container Related
1130 , toHashMapIO
1231 )
1332where
@@ -17,27 +36,26 @@ import Data.HashMap.Strict (HashMap)
1736import Data.Hashable (Hashable)
1837import Streamly.Data.Fold
1938import Streamly.Internal.Data.Fold (toContainerIO)
39+import Streamly.Internal.Data.Fold.Concurrent
2040import Streamly.Internal.Data.IsMap.HashMap ()
2141
2242-- | Split the input stream based on a hashable component of the key field and
2343-- fold each split using the given fold. Useful for map/reduce, bucketizing
2444-- the input in different bins or for generating histograms.
2545--
26−-- Example:
27−--
2846-- >>> import Data.HashMap.Strict (HashMap, fromList)
2947-- >>> import qualified Streamly.Data.Fold.Prelude as Fold
3048-- >>> import qualified Streamly.Data.Stream as Stream
31−-- >>> import Streamly.Data.Fold.Prelude (toHashMapIO)
32−-- >>> :{
33−-- do
34−-- let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
35−-- classify = toHashMapIO fst (Fold.lmap snd Fold.toList)
36−-- x <- Stream.fold classify input :: IO (HashMap String [Double])
37−-- let y = fromList [("ONE",[1.0,1.1]),("TWO",[2.0,2.2])]
38−-- return (x == y)
39−-- :}
40−-- True
49+--
50+-- Consider a stream of key value pairs:
51+--
52+-- >>> input = Stream.fromList [("k1",1),("k1",1.1),("k2",2), ("k2",2.2)]
53+--
54+-- Classify each key to a different hash bin and fold the bins:
55+--
56+-- >>> classify = Fold.toHashMapIO fst (Fold.lmap snd Fold.toList)
57+-- >>> Stream.fold classify input :: IO (HashMap String [Double])
58+-- fromList [("k1",[1.0,1.1]),("k2",[2.0,2.2])]
4159--
4260-- /Pre-release/
4361--