@@ -6,8 +6,27 @@
6-- Stability : released
6-- Stability : released
7-- Portability : GHC
7-- Portability : GHC
9+-- All Fold related combinators including the streamly-core
10+-- "Streamly.Data.Fold" module, concurrency, unordered container operations.
9module Streamly.Data.Fold.Prelude
12module Streamly.Data.Fold.Prelude
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
29+ -- * Container Related
11 , toHashMapIO
30 , toHashMapIO
@@ -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 ()
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.
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:
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)]
54+-- Classify each key to a different hash bin and fold the bins:
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])]
42-- /Pre-release/
60-- /Pre-release/