Hoogle Search
Within LTS Haskell 24.68 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
foldMap :: forall (m :: Type -> Type) b a . (Monad m, Monoid b) => (a -> b) -> Fold m a bstreamly-core Streamly.Internal.Data.Fold Definition:
>>> foldMap f = Fold.lmap f Fold.mconcat
Make a fold from a pure function that folds the output of the function using mappend and mempty.>>> sum = Fold.foldMap Data.Monoid.Sum >>> Stream.fold sum $ Stream.enumerateFromTo 1 10 Sum {getSum = 55}foldMapM :: (Monad m, Monoid b) => (a -> m b) -> Fold m a bstreamly-core Streamly.Internal.Data.Fold Definition:
>>> foldMapM f = Fold.lmapM f Fold.mconcat
Make a fold from a monadic function that folds the output of the function using mappend and mempty.>>> sum = Fold.foldMapM (return . Data.Monoid.Sum) >>> Stream.fold sum $ Stream.enumerateFromTo 1 10 Sum {getSum = 55}-
streamly-core Streamly.Internal.Data.Fold Given an input stream of key value pairs and a fold for values, fold all the values belonging to each key. Useful for map/reduce, bucketizing the input in different bins or for generating histograms. Definition:
>>> kvToMap = Fold.toMap fst . Fold.lmap snd
Example:>>> :{ let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)] in Stream.fold (Fold.kvToMap Fold.toList) input :} fromList [("ONE",[1.0,1.1]),("TWO",[2.0,2.2])]Pre-release lmap :: forall a b (m :: Type -> Type) r . (a -> b) -> Fold m b r -> Fold m a rstreamly-core Streamly.Internal.Data.Fold lmap f fold maps the function f on the input of the fold. Definition:
>>> lmap = Fold.lmapM return
Example:>>> sumSquared = Fold.lmap (\x -> x * x) Fold.sum >>> Stream.fold sumSquared (Stream.enumerateFromTo 1 100) 338350
lmapM :: Monad m => (a -> m b) -> Fold m b r -> Fold m a rstreamly-core Streamly.Internal.Data.Fold lmapM f fold maps the monadic function f on the input of the fold.
rmapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a cstreamly-core Streamly.Internal.Data.Fold Map a monadic function on the output of a fold.
rollingMapM :: Monad m => (Maybe a -> a -> m b) -> Fold m a bstreamly-core Streamly.Internal.Data.Fold Apply a function on every two successive elements of a stream. The first argument of the map function is the previous element and the second argument is the current element. When processing the very first element in the stream, the previous element is Nothing. Pre-release
-
streamly-core Streamly.Internal.Data.Fold Split the input stream based on a key field and fold each split using the given fold. Useful for map/reduce, bucketizing the input in different bins or for generating histograms. Example:
>>> import Data.Map.Strict (Map) >>> :{ let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)] classify = Fold.toMap fst (Fold.lmap snd Fold.toList) in Stream.fold classify input :: IO (Map String [Double]) :} fromList [("ONE",[1.0,1.1]),("TWO",[2.0,2.2])]Once the classifier fold terminates for a particular key any further inputs in that bucket are ignored. Space used is proportional to the number of keys seen till now and monotonically increases because it stores whether a key has been seen or not. See demuxToMap for a more powerful version where you can use a different fold for each key. A simpler version of toMap retaining only the last value for a key can be written as:>>> toMap = Fold.foldl' (\kv (k, v) -> Map.insert k v kv) Map.empty
Stops: never Pre-release -
streamly-core Streamly.Internal.Data.Fold Same as toMap but maybe faster because it uses mutable cells as fold accumulators in the Map.
-
streamly-core Streamly.Internal.Data.Fold Map a function on the incoming as well as outgoing element of a rolling window fold.
>>> lmap f = Fold.lmap (bimap f (f <$>))