Hoogle Search
Within LTS Haskell 24.6 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
mconcatMapM :: (Monad m, Monoid b) => (a -> m b) -> [a] -> m bdistribution-opensuse OpenSuse.Prelude A version of mconcatMap that works with a monadic predicate.
-
github GitHub.Internal.Prelude A map from keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
bifmap :: Functor f => (a <-> b) -> f a <-> f binvertible Data.Invertible.Prelude Lift both sides of an bijection over a functor using fmap. We name this bifmap in deference to the more useful fmap.
fmap :: Functor f => (a <-> b) -> f a -> f binvertible Data.Invertible.Prelude No documentation available.
-
streamly Streamly.Data.Fold.Prelude Split the input stream based on a hashable component of the key field and fold each split using the given fold. Useful for map/reduce, bucketizing the input in different bins or for generating histograms.
>>> import Data.HashMap.Strict (HashMap, fromList) >>> import qualified Streamly.Data.Fold.Prelude as Fold >>> import qualified Streamly.Data.Stream as Stream
Consider a stream of key value pairs:>>> input = Stream.fromList [("k1",1),("k1",1.1),("k2",2), ("k2",2.2)]
Classify each key to a different hash bin and fold the bins:>>> classify = Fold.toHashMapIO fst (Fold.lmap snd Fold.toList) >>> Stream.fold classify input :: IO (HashMap String [Double]) fromList [("k2",[2.0,2.2]),("k1",[1.0,1.1])]
Pre-release -
streamly Streamly.Data.Stream.Prelude Map each element of the input to a stream and then concurrently evaluate and concatenate the resulting streams. Multiple streams may be evaluated concurrently but earlier streams are perferred. Output from the streams are used as they arrive. Definition:
>>> parConcatMap modifier f stream = Stream.parConcat modifier $ fmap f stream
Examples:>>> f cfg xs = Stream.fold Fold.toList $ Stream.parConcatMap cfg id $ Stream.fromList xs
The following streams finish in 4 seconds:>>> stream1 = Stream.fromEffect (delay 4) >>> stream2 = Stream.fromEffect (delay 2) >>> stream3 = Stream.fromEffect (delay 1) >>> f id [stream1, stream2, stream3] 1 sec 2 sec 4 sec [1,2,4]
Limiting threads to 2 schedules the third stream only after one of the first two has finished, releasing a thread:>>> f (Stream.maxThreads 2) [stream1, stream2, stream3] ... [2,1,4]
When used with a Single thread it behaves like serial concatMap:>>> f (Stream.maxThreads 1) [stream1, stream2, stream3] ... [4,2,1]
>>> stream1 = Stream.fromList [1,2,3] >>> stream2 = Stream.fromList [4,5,6] >>> f (Stream.maxThreads 1) [stream1, stream2] [1,2,3,4,5,6]
Schedule all streams in a round robin fashion over the available threads:>>> f cfg xs = Stream.fold Fold.toList $ Stream.parConcatMap (Stream.interleaved True . cfg) id $ Stream.fromList xs
>>> stream1 = Stream.fromList [1,2,3] >>> stream2 = Stream.fromList [4,5,6] >>> f (Stream.maxThreads 1) [stream1, stream2] [1,4,2,5,3,6]
parMapM :: MonadAsync m => (Config -> Config) -> (a -> m b) -> Stream m a -> Stream m bstreamly Streamly.Data.Stream.Prelude Definition:
>>> parMapM modifier f = Stream.parConcatMap modifier (Stream.fromEffect . f)
For example, the following finishes in 3 seconds (as opposed to 6 seconds) because all actions run in parallel. Even though results are available out of order they are ordered due to the config option:>>> f x = delay x >> return x >>> Stream.fold Fold.toList $ Stream.parMapM (Stream.ordered True) f $ Stream.fromList [3,2,1] 1 sec 2 sec 3 sec [3,2,1]
-
streamly Streamly.Internal.Data.Stream.Prelude Map each element of the input to a stream and then concurrently evaluate and concatenate the resulting streams. Multiple streams may be evaluated concurrently but earlier streams are perferred. Output from the streams are used as they arrive. Definition:
>>> parConcatMap modifier f stream = Stream.parConcat modifier $ fmap f stream
Examples:>>> f cfg xs = Stream.fold Fold.toList $ Stream.parConcatMap cfg id $ Stream.fromList xs
The following streams finish in 4 seconds:>>> stream1 = Stream.fromEffect (delay 4) >>> stream2 = Stream.fromEffect (delay 2) >>> stream3 = Stream.fromEffect (delay 1) >>> f id [stream1, stream2, stream3] 1 sec 2 sec 4 sec [1,2,4]
Limiting threads to 2 schedules the third stream only after one of the first two has finished, releasing a thread:>>> f (Stream.maxThreads 2) [stream1, stream2, stream3] ... [2,1,4]
When used with a Single thread it behaves like serial concatMap:>>> f (Stream.maxThreads 1) [stream1, stream2, stream3] ... [4,2,1]
>>> stream1 = Stream.fromList [1,2,3] >>> stream2 = Stream.fromList [4,5,6] >>> f (Stream.maxThreads 1) [stream1, stream2] [1,2,3,4,5,6]
Schedule all streams in a round robin fashion over the available threads:>>> f cfg xs = Stream.fold Fold.toList $ Stream.parConcatMap (Stream.interleaved True . cfg) id $ Stream.fromList xs
>>> stream1 = Stream.fromList [1,2,3] >>> stream2 = Stream.fromList [4,5,6] >>> f (Stream.maxThreads 1) [stream1, stream2] [1,4,2,5,3,6]
parMapM :: MonadAsync m => (Config -> Config) -> (a -> m b) -> Stream m a -> Stream m bstreamly Streamly.Internal.Data.Stream.Prelude Definition:
>>> parMapM modifier f = Stream.parConcatMap modifier (Stream.fromEffect . f)
For example, the following finishes in 3 seconds (as opposed to 6 seconds) because all actions run in parallel. Even though results are available out of order they are ordered due to the config option:>>> f x = delay x >> return x >>> Stream.fold Fold.toList $ Stream.parMapM (Stream.ordered True) f $ Stream.fromList [3,2,1] 1 sec 2 sec 3 sec [3,2,1]
-
streamly Streamly.Prelude 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.concatMapWith Stream.serial f >>> concatMap f = Stream.concat . Stream.map f