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.

  1. concatMapM :: Monad m => (a -> m (Stream m b)) -> Stream m a -> Stream m b

    streamly-core Streamly.Data.Stream

    Map a stream producing monadic function on each element of the stream and then flatten the results into a single stream. Since the stream generation function is monadic, unlike concatMap, it can produce an effect at the beginning of each iteration of the inner loop. See unfoldMany for a fusible alternative.

  2. concatMapWith :: forall (m :: Type -> Type) b a . (StreamK m b -> StreamK m b -> StreamK m b) -> (a -> StreamK m b) -> StreamK m a -> StreamK m b

    streamly-core Streamly.Data.StreamK

    Perform a concatMap using a specified concat strategy. The first argument specifies a merge or concat function that is used to merge the streams generated by the map function.

  3. mergeMapWith :: forall (m :: Type -> Type) b a . (StreamK m b -> StreamK m b -> StreamK m b) -> (a -> StreamK m b) -> StreamK m a -> StreamK m b

    streamly-core Streamly.Data.StreamK

    Combine streams in pairs using a binary combinator, the resulting streams are then combined again in pairs recursively until we get to a single combined stream. The composition would thus form a binary tree. For example, you can sort a stream using merge sort like this:

    >>> s = StreamK.fromStream $ Stream.fromList [5,1,7,9,2]
    
    >>> generate = StreamK.fromPure
    
    >>> combine = StreamK.mergeBy compare
    
    >>> Stream.fold Fold.toList $ StreamK.toStream $ StreamK.mergeMapWith combine generate s
    [1,2,5,7,9]
    
    Note that if the stream length is not a power of 2, the binary tree composed by mergeMapWith would not be balanced, which may or may not be important depending on what you are trying to achieve. Caution: the stream of streams must be finite Pre-release

  4. lmap :: forall a c (m :: Type -> Type) b . (a -> c) -> Unfold m c b -> Unfold m a b

    streamly-core Streamly.Data.Unfold

    Map a function on the input argument of the Unfold.

    >>> u = Unfold.lmap (fmap (+1)) Unfold.fromList
    
    >>> Unfold.fold Fold.toList u [1..5]
    [2,3,4,5,6]
    
    lmap f = Unfold.many (Unfold.function f)
    

  5. lmapM :: Monad m => (a -> m c) -> Unfold m c b -> Unfold m a b

    streamly-core Streamly.Data.Unfold

    Map an action on the input argument of the Unfold.

    lmapM f = Unfold.many (Unfold.functionM f)
    

  6. 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.Internal.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

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

    streamly-core Streamly.Internal.Data.Fold

    Fold a stream of key value pairs using a function that maps keys to folds. Definition:

    >>> demuxKvToMap f = Fold.demuxToContainer fst (Fold.lmap snd . f)
    
    Example:
    >>> import Data.Map (Map)
    
    >>> :{
    let f "SUM" = return Fold.sum
    f _ = return Fold.product
    input = Stream.fromList [("SUM",1),("PRODUCT",2),("SUM",3),("PRODUCT",4)]
    in Stream.fold (Fold.demuxKvToMap f) input :: IO (Map String Int)
    :}
    fromList [("PRODUCT",8),("SUM",4)]
    
    Pre-release

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

    streamly-core Streamly.Internal.Data.Fold

    This collects all the results of demux in a Map.

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

    streamly-core Streamly.Internal.Data.Fold

    Same as demuxToMap but uses demuxIO for better performance.

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

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

Page 1087 of many | Previous | Next