pnpm
Version:
Fast, disk space efficient package manager
27 lines (23 loc) • 987 B
JavaScript
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
import { mergeConcurrently, mergeMapConcurrently } from './mergeConcurrently'
/**
* Map each value in the stream to a new stream, and merge it into the
* returned outer stream. Event arrival times are preserved.
* @param {function(x:*):Stream} f chaining function, must return a Stream
* @param {Stream} stream
* @returns {Stream} new stream containing all events from each stream returned by f
*/
export function flatMap (f, stream) {
return mergeMapConcurrently(f, Infinity, stream)
}
/**
* Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
* streams to the outer. Event arrival times are preserved.
* @param {Stream<Stream<X>>} stream stream of streams
* @returns {Stream<X>} new stream containing all events of all inner streams
*/
export function join (stream) {
return mergeConcurrently(Infinity, stream)
}