Hoogle Search

Within LTS Haskell 24.45 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. concatMap :: forall (m :: Type -> Type) b a c . Monad m => (b -> Fold m a c) -> Fold m a b -> Fold m a c

    streamly-core Streamly.Data.Fold

    Map a Fold returning function on the result of a Fold and run the returned fold. This operation can be used to express data dependencies between fold operations. Let's say the first element in the stream is a count of the following elements that we have to add, then:

    >>> import Data.Maybe (fromJust)
    
    >>> count = fmap fromJust Fold.one
    
    >>> total n = Fold.take n Fold.sum
    
    >>> Stream.fold (Fold.concatMap total count) $ Stream.fromList [10,9..1]
    45
    
    This does not fuse completely, see refold for a fusible alternative. Time: O(n^2) where n is the number of compositions. See also: foldIterateM, refold

  2. demuxToMap :: (Monad m, Ord k) => (a -> k) -> (a -> m (Fold m a b)) -> Fold m a (Map k b)

    streamly-core Streamly.Data.Fold

    This collects all the results of demux in a Map.

  3. demuxToMapIO :: (MonadIO m, Ord k) => (a -> k) -> (a -> m (Fold m a b)) -> Fold m a (Map k b)

    streamly-core Streamly.Data.Fold

    Same as demuxToMap but uses demuxIO for better performance.

  4. drainMapM :: Monad m => (a -> m b) -> Fold m a ()

    streamly-core Streamly.Data.Fold

    Definitions:

    >>> drainMapM f = Fold.lmapM f Fold.drain
    
    >>> drainMapM f = Fold.foldMapM (void . f)
    
    Drain all input after passing it through a monadic function. This is the dual of mapM_ on stream producers.

  5. foldMap :: forall (m :: Type -> Type) b a . (Monad m, Monoid b) => (a -> b) -> Fold m a b

    streamly-core Streamly.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}
    

  6. foldMapM :: (Monad m, Monoid b) => (a -> m b) -> Fold m a b

    streamly-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}
    

  7. lmap :: forall a b (m :: Type -> Type) r . (a -> b) -> Fold m b r -> Fold m a r

    streamly-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
    

  8. lmapM :: Monad m => (a -> m b) -> Fold m b r -> Fold m a r

    streamly-core Streamly.Data.Fold

    lmapM f fold maps the monadic function f on the input of the fold.

  9. rmapM :: Monad m => (b -> m c) -> Fold m a b -> Fold m a c

    streamly-core Streamly.Data.Fold

    Map a monadic function on the output of a fold.

  10. toMap :: forall (m :: Type -> Type) k a b . (Monad m, Ord k) => (a -> k) -> Fold m a b -> Fold m a (Map k b)

    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

Page 1086 of many | Previous | Next