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.
foldMapM :: (Monad m, Monoid b) => (a -> m b) -> Fold m a bstreamly-core Streamly.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}lmap :: forall a b (m :: Type -> Type) r . (a -> b) -> Fold m b r -> Fold m a rstreamly-core Streamly.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.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.Data.Fold Map a monadic function on the output of a fold.
-
streamly-core Streamly.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.Data.Fold Same as toMap but maybe faster because it uses mutable cells as fold accumulators in the Map.
lmap :: forall a b (m :: Type -> Type) r . (a -> b) -> Parser b m r -> Parser a m rstreamly-core Streamly.Data.Parser lmap f parser maps the function f on the input of the parser.
>>> Stream.parse (Parser.lmap (\x -> x * x) (Parser.fromFold Fold.sum)) (Stream.enumerateFromTo 1 100) Right 338350
lmap = Parser.lmapM return
lmapM :: Monad m => (a -> m b) -> Parser b m r -> Parser a m rstreamly-core Streamly.Data.Parser lmapM f parser maps the monadic function f on the input of the parser.
rmapM :: Monad m => (b -> m c) -> Parser a m b -> Parser a m cstreamly-core Streamly.Data.Parser rmapM f parser maps the monadic function f on the output of the parser.
>>> rmap = fmap
-
streamly-core Streamly.Data.Stream Map a stream producing function on each element of the stream and then flatten the results into a single stream.
>>> concatMap f = Stream.concatMapM (return . f) >>> concatMap f = Stream.concat . fmap f >>> concatMap f = Stream.unfoldMany (Unfold.lmap f Unfold.fromStream)
See unfoldMany for a fusible alternative.