2-- Module : Streamly.Data.Fold.Prelude
3-- Copyright : (c) 2021 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
9module Streamly.Data.Fold.Prelude
10 ( module Streamly.Data.Fold
15import Control.Monad.IO.Class (MonadIO)
16import Data.HashMap.Strict (HashMap)
17import Data.Hashable (Hashable)
18import Streamly.Data.Fold
19import Streamly.Internal.Data.Fold.Container (toContainerIO)
20import Streamly.Internal.Data.IsMap.HashMap ()
22-- | 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
24-- the input in different bins or for generating histograms.
28-- >>> import Data.HashMap.Strict (HashMap, fromList)
29-- >>> import qualified Streamly.Data.Fold.Prelude as Fold
30-- >>> import qualified Streamly.Data.Stream as Stream
31-- >>> import Streamly.Data.Fold.Prelude (toHashMapIO)
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])]
44{-# INLINE toHashMapIO #-}
45toHashMapIO :: (MonadIO m, Hashable k, Ord k) =>
46 (a -> k) -> Fold m a b -> Fold m a (HashMap k b)
47toHashMapIO = toContainerIO
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list