on master help sign in
Update the Fold.Prelude module, export concurrent ops
0285479Harendra Kumar
src/Streamly/Data/Fold/Prelude.hs+31−13
@@ -6,8 +6,27 @@
6-- Stability : released
6-- Stability : released
7-- Portability : GHC
7-- Portability : GHC
8--
8--
9+-- All Fold related combinators including the streamly-core
10+-- "Streamly.Data.Fold" module, concurrency, unordered container operations.
11+--
9module Streamly.Data.Fold.Prelude
12module Streamly.Data.Fold.Prelude
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.
10− ( module Streamly.Data.Fold
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
11 , toHashMapIO
30 , toHashMapIO
12 )
31 )
13where
32where
@@ -17,27 +36,26 @@ import Data.HashMap.Strict (HashMap)
17import Data.Hashable (Hashable)
36import Data.Hashable (Hashable)
18import Streamly.Data.Fold
37import Streamly.Data.Fold
19import Streamly.Internal.Data.Fold (toContainerIO)
38import Streamly.Internal.Data.Fold (toContainerIO)
39+import Streamly.Internal.Data.Fold.Concurrent
20import Streamly.Internal.Data.IsMap.HashMap ()
40import Streamly.Internal.Data.IsMap.HashMap ()
21
41
22-- | Split the input stream based on a hashable component of the key field and
42-- | Split the input stream based on a hashable component of the key field and
23-- fold each split using the given fold. Useful for map/reduce, bucketizing
43-- fold each split using the given fold. Useful for map/reduce, bucketizing
24-- the input in different bins or for generating histograms.
44-- the input in different bins or for generating histograms.
25--
45--
26−-- Example:
27−--
28-- >>> import Data.HashMap.Strict (HashMap, fromList)
46-- >>> import Data.HashMap.Strict (HashMap, fromList)
29-- >>> import qualified Streamly.Data.Fold.Prelude as Fold
47-- >>> import qualified Streamly.Data.Fold.Prelude as Fold
30-- >>> import qualified Streamly.Data.Stream as Stream
48-- >>> import qualified Streamly.Data.Stream as Stream
31−-- >>> import Streamly.Data.Fold.Prelude (toHashMapIO)
49+--
32−-- >>> :{
50+-- Consider a stream of key value pairs:
33−-- do
51+--
34−-- let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
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+--
35−-- classify = toHashMapIO fst (Fold.lmap snd Fold.toList)
56+-- >>> classify = Fold.toHashMapIO fst (Fold.lmap snd Fold.toList)
36−-- x <- Stream.fold classify input :: IO (HashMap String [Double])
57+-- >>> Stream.fold classify input :: IO (HashMap String [Double])
37−-- let y = fromList [("ONE",[1.0,1.1]),("TWO",[2.0,2.2])]
58+-- fromList [("k1",[1.0,1.1]),("k2",[2.0,2.2])]
38−-- return (x == y)
39−-- :}
40−-- True
41--
59--
42-- /Pre-release/
60-- /Pre-release/
43--
61--