veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
1,437 lines (1,436 loc) • 83.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fromPubSub = exports.fromIteratorSucceed = exports.fromIterableEffect = exports.fromIterable = exports.fromEffectOption = exports.fromEffect = exports.fromChunks = exports.fromChunkQueue = exports.fromChunkPubSub = exports.fromChunk = exports.fromChannel = exports.fromAsyncIterable = exports.forever = exports.flattenTake = exports.flattenIterables = exports.flattenExitOption = exports.flattenEffect = exports.flattenChunks = exports.flatten = exports.flatMap = exports.findEffect = exports.find = exports.finalizer = exports.filterMapWhileEffect = exports.filterMapWhile = exports.filterMapEffect = exports.filterMap = exports.filterEffect = exports.filter = exports.failSync = exports.failCauseSync = exports.failCause = exports.fail = exports.execute = exports.ensuringWith = exports.ensuring = exports.encodeText = exports.empty = exports.either = exports.dropWhileEffect = exports.dropWhile = exports.dropUntilEffect = exports.dropUntil = exports.dropRight = exports.drop = exports.drainFork = exports.drain = exports.distributedWithDynamic = exports.distributedWith = exports.dieSync = exports.dieMessage = exports.die = exports.decodeText = exports.debounce = exports.crossWith = exports.crossRight = exports.crossLeft = exports.cross = exports.contextWithStream = exports.contextWithEffect = exports.contextWith = exports.context = exports.concatAll = exports.concat = exports.combineChunks = exports.combine = exports.chunksWith = exports.chunks = exports.changesWithEffect = exports.changesWith = exports.changes = exports.catchTags = exports.catchTag = exports.catchSomeCause = exports.catchSome = exports.catchAllCause = exports.catchAll = exports.bufferChunks = exports.buffer = exports.broadcastedQueuesDynamic = exports.broadcastedQueues = exports.broadcastDynamic = exports.broadcast = exports.branchAfter = exports.bindTo = exports.bindEffect = exports.bind = exports.asyncScoped = exports.asyncEffect = exports.async = exports.as = exports.aggregateWithinEither = exports.aggregateWithin = exports.aggregate = exports.acquireRelease = exports.accumulateChunks = exports.accumulate = exports.StreamTypeId = exports.Do = exports.DefaultChunkSize = void 0;
exports.runFoldWhileEffect = exports.runFoldWhile = exports.runFoldScopedEffect = exports.runFoldScoped = exports.runFoldEffect = exports.runFold = exports.runDrain = exports.runCount = exports.runCollect = exports.run = exports.retry = exports.repeatWith = exports.repeatValue = exports.repeatElementsWith = exports.repeatElements = exports.repeatEither = exports.repeatEffectWithSchedule = exports.repeatEffectOption = exports.repeatEffectChunkOption = exports.repeatEffectChunk = exports.repeatEffect = exports.repeat = exports.refineOrDieWith = exports.refineOrDie = exports.rechunk = exports.range = exports.provideSomeLayer = exports.provideServiceStream = exports.provideServiceEffect = exports.provideService = exports.provideLayer = exports.provideContext = exports.prepend = exports.pipeThroughChannelOrFail = exports.pipeThroughChannel = exports.pipeThrough = exports.peel = exports.partitionEither = exports.partition = exports.paginateEffect = exports.paginateChunkEffect = exports.paginateChunk = exports.paginate = exports.orElseSucceed = exports.orElseIfEmptyStream = exports.orElseIfEmptyChunk = exports.orElseIfEmpty = exports.orElseFail = exports.orElseEither = exports.orElse = exports.orDieWith = exports.orDie = exports.onError = exports.onDone = exports.never = exports.mkString = exports.mergeWith = exports.mergeRight = exports.mergeLeft = exports.mergeEither = exports.mergeAll = exports.merge = exports.mapInputContext = exports.mapErrorCause = exports.mapError = exports.mapEffect = exports.mapConcatEffect = exports.mapConcatChunkEffect = exports.mapConcatChunk = exports.mapConcat = exports.mapChunksEffect = exports.mapChunks = exports.mapBoth = exports.mapAccumEffect = exports.mapAccum = exports.map = exports.make = exports.let = exports.iterate = exports.intersperseAffixes = exports.intersperse = exports.interruptWhenDeferred = exports.interruptWhen = exports.interruptAfter = exports.interleaveWith = exports.interleave = exports.identity = exports.haltWhenDeferred = exports.haltWhen = exports.haltAfter = exports.groupedWithin = exports.grouped = exports.groupByKey = exports.groupBy = exports.groupAdjacentBy = exports.fromSchedule = exports.fromReadableStreamByob = exports.fromReadableStream = exports.fromQueue = exports.fromPull = void 0;
exports.zipWithPreviousAndNext = exports.zipWithPrevious = exports.zipWithNext = exports.zipWithIndex = exports.zipWithChunks = exports.zipWith = exports.zipRight = exports.zipLeft = exports.zipLatestWith = exports.zipLatest = exports.zipFlatten = exports.zipAllWith = exports.zipAllSortedByKeyWith = exports.zipAllSortedByKeyRight = exports.zipAllSortedByKeyLeft = exports.zipAllSortedByKey = exports.zipAllRight = exports.zipAllLeft = exports.zipAll = exports.zip = exports.withSpan = exports.whenEffect = exports.whenCaseEffect = exports.whenCase = exports.when = exports.updateService = exports.unwrapScoped = exports.unwrap = exports.unit = exports.unfoldEffect = exports.unfoldChunkEffect = exports.unfoldChunk = exports.unfold = exports.transduce = exports.toReadableStream = exports.toQueueOfElements = exports.toQueue = exports.toPull = exports.toPubSub = exports.toChannel = exports.timeoutTo = exports.timeoutFailCause = exports.timeoutFail = exports.timeout = exports.tick = exports.throttleEffect = exports.throttle = exports.tapSink = exports.tapErrorCause = exports.tapError = exports.tapBoth = exports.tap = exports.takeWhile = exports.takeUntilEffect = exports.takeUntil = exports.takeRight = exports.take = exports.sync = exports.suspend = exports.succeed = exports.splitOnChunk = exports.splitLines = exports.split = exports.someOrFail = exports.someOrElse = exports.some = exports.slidingSize = exports.sliding = exports.scoped = exports.scheduleWith = exports.schedule = exports.scanReduceEffect = exports.scanReduce = exports.scanEffect = exports.scan = exports.runSum = exports.runScoped = exports.runLast = exports.runIntoQueueScoped = exports.runIntoQueueElementsScoped = exports.runIntoQueue = exports.runIntoPubSubScoped = exports.runIntoPubSub = exports.runHead = exports.runForEachWhileScoped = exports.runForEachWhile = exports.runForEachScoped = exports.runForEachChunkScoped = exports.runForEachChunk = exports.runForEach = exports.runFoldWhileScopedEffect = exports.runFoldWhileScoped = void 0;
var _groupBy = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/groupBy.js"));
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/stream.js"));
function _getRequireWildcardCache(e) {
if ("function" != typeof WeakMap) return null;
var r = new WeakMap(),
t = new WeakMap();
return (_getRequireWildcardCache = function (e) {
return e ? t : r;
})(e);
}
function _interopRequireWildcard(e, r) {
if (!r && e && e.__esModule) return e;
if (null === e || "object" != typeof e && "function" != typeof e) return {
default: e
};
var t = _getRequireWildcardCache(r);
if (t && t.has(e)) return t.get(e);
var n = {
__proto__: null
},
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
}
return n.default = e, t && t.set(e, n), n;
}
/**
* @since 2.0.0
* @category symbols
*/
const StreamTypeId = exports.StreamTypeId = internal.StreamTypeId;
/**
* The default chunk size used by the various combinators and constructors of
* `Stream`.
*
* @since 2.0.0
* @category constants
*/
const DefaultChunkSize = exports.DefaultChunkSize = internal.DefaultChunkSize;
/**
* Collects each underlying Chunk of the stream into a new chunk, and emits it
* on each pull.
*
* @since 2.0.0
* @category utils
*/
const accumulate = exports.accumulate = internal.accumulate;
/**
* Re-chunks the elements of the stream by accumulating each underlying chunk.
*
* @since 2.0.0
* @category utils
*/
const accumulateChunks = exports.accumulateChunks = internal.accumulateChunks;
/**
* Creates a stream from a single value that will get cleaned up after the
* stream is consumed.
*
* @since 2.0.0
* @category constructors
*/
const acquireRelease = exports.acquireRelease = internal.acquireRelease;
/**
* Aggregates elements of this stream using the provided sink for as long as
* the downstream operators on the stream are busy.
*
* This operator divides the stream into two asynchronous "islands". Operators
* upstream of this operator run on one fiber, while downstream operators run
* on another. Whenever the downstream fiber is busy processing elements, the
* upstream fiber will feed elements into the sink until it signals
* completion.
*
* Any sink can be used here, but see `Sink.foldWeightedEffect` and
* `Sink.foldUntilEffect` for sinks that cover the common usecases.
*
* @since 2.0.0
* @category utils
*/
const aggregate = exports.aggregate = internal.aggregate;
/**
* Like `aggregateWithinEither`, but only returns the `Right` results.
*
* @param sink A `Sink` used to perform the aggregation.
* @param schedule A `Schedule` used to signal when to stop the aggregation.
* @since 2.0.0
* @category utils
*/
const aggregateWithin = exports.aggregateWithin = internal.aggregateWithin;
/**
* Aggregates elements using the provided sink until it completes, or until
* the delay signalled by the schedule has passed.
*
* This operator divides the stream into two asynchronous islands. Operators
* upstream of this operator run on one fiber, while downstream operators run
* on another. Elements will be aggregated by the sink until the downstream
* fiber pulls the aggregated value, or until the schedule's delay has passed.
*
* Aggregated elements will be fed into the schedule to determine the delays
* between pulls.
*
* @param sink A `Sink` used to perform the aggregation.
* @param schedule A `Schedule` used to signal when to stop the aggregation.
* @since 2.0.0
* @category utils
*/
const aggregateWithinEither = exports.aggregateWithinEither = internal.aggregateWithinEither;
/**
* Maps the success values of this stream to the specified constant value.
*
* @since 2.0.0
* @category mapping
*/
const as = exports.as = internal.as;
const _async = exports.async = internal._async;
/**
* Creates a stream from an asynchronous callback that can be called multiple
* times The registration of the callback itself returns an effect. The
* optionality of the error type `E` can be used to signal the end of the
* stream, by setting it to `None`.
*
* @since 2.0.0
* @category constructors
*/
const asyncEffect = exports.asyncEffect = internal.asyncEffect;
/**
* Creates a stream from an asynchronous callback that can be called multiple
* times. The registration of the callback itself returns an a scoped
* resource. The optionality of the error type `E` can be used to signal the
* end of the stream, by setting it to `None`.
*
* @since 2.0.0
* @category constructors
*/
const asyncScoped = exports.asyncScoped = internal.asyncScoped;
/**
* Returns a `Stream` that first collects `n` elements from the input `Stream`,
* and then creates a new `Stream` using the specified function, and sends all
* the following elements through that.
*
* @since 2.0.0
* @category sequencing
*/
const branchAfter = exports.branchAfter = internal.branchAfter;
/**
* Fan out the stream, producing a list of streams that have the same elements
* as this stream. The driver stream will only ever advance the `maximumLag`
* chunks before the slowest downstream stream.
*
* @since 2.0.0
* @category utils
*/
const broadcast = exports.broadcast = internal.broadcast;
/**
* Fan out the stream, producing a dynamic number of streams that have the
* same elements as this stream. The driver stream will only ever advance the
* `maximumLag` chunks before the slowest downstream stream.
*
* @since 2.0.0
* @category utils
*/
const broadcastDynamic = exports.broadcastDynamic = internal.broadcastDynamic;
/**
* Converts the stream to a scoped list of queues. Every value will be
* replicated to every queue with the slowest queue being allowed to buffer
* `maximumLag` chunks before the driver is back pressured.
*
* Queues can unsubscribe from upstream by shutting down.
*
* @since 2.0.0
* @category utils
*/
const broadcastedQueues = exports.broadcastedQueues = internal.broadcastedQueues;
/**
* Converts the stream to a scoped dynamic amount of queues. Every chunk will
* be replicated to every queue with the slowest queue being allowed to buffer
* `maximumLag` chunks before the driver is back pressured.
*
* Queues can unsubscribe from upstream by shutting down.
*
* @since 2.0.0
* @category utils
*/
const broadcastedQueuesDynamic = exports.broadcastedQueuesDynamic = internal.broadcastedQueuesDynamic;
/**
* Allows a faster producer to progress independently of a slower consumer by
* buffering up to `capacity` elements in a queue.
*
* @note This combinator destroys the chunking structure. It's recommended to
* use rechunk afterwards. Additionally, prefer capacities that are powers
* of 2 for better performance.
* @since 2.0.0
* @category utils
*/
const buffer = exports.buffer = internal.buffer;
/**
* Allows a faster producer to progress independently of a slower consumer by
* buffering up to `capacity` chunks in a queue.
*
* @note Prefer capacities that are powers of 2 for better performance.
* @since 2.0.0
* @category utils
*/
const bufferChunks = exports.bufferChunks = internal.bufferChunks;
/**
* Switches over to the stream produced by the provided function in case this
* one fails with a typed error.
*
* @since 2.0.0
* @category error handling
*/
const catchAll = exports.catchAll = internal.catchAll;
/**
* Switches over to the stream produced by the provided function in case this
* one fails. Allows recovery from all causes of failure, including
* interruption if the stream is uninterruptible.
*
* @since 2.0.0
* @category error handling
*/
const catchAllCause = exports.catchAllCause = internal.catchAllCause;
/**
* Switches over to the stream produced by the provided function in case this
* one fails with some typed error.
*
* @since 2.0.0
* @category error handling
*/
const catchSome = exports.catchSome = internal.catchSome;
/**
* Switches over to the stream produced by the provided function in case this
* one fails with an error matching the given `_tag`.
*
* @since 2.0.0
* @category error handling
*/
const catchTag = exports.catchTag = internal.catchTag;
/**
* Switches over to the stream produced by one of the provided functions, in
* case this one fails with an error matching one of the given `_tag`'s.
*
* @since 2.0.0
* @category error handling
*/
const catchTags = exports.catchTags = internal.catchTags;
/**
* Switches over to the stream produced by the provided function in case this
* one fails with some errors. Allows recovery from all causes of failure,
* including interruption if the stream is uninterruptible.
*
* @since 2.0.0
* @category error handling
*/
const catchSomeCause = exports.catchSomeCause = internal.catchSomeCause;
/**
* Returns a new stream that only emits elements that are not equal to the
* previous element emitted, using natural equality to determine whether two
* elements are equal.
*
* @since 2.0.0
* @category utils
*/
const changes = exports.changes = internal.changes;
/**
* Returns a new stream that only emits elements that are not equal to the
* previous element emitted, using the specified function to determine whether
* two elements are equal.
*
* @since 2.0.0
* @category utils
*/
const changesWith = exports.changesWith = internal.changesWith;
/**
* Returns a new stream that only emits elements that are not equal to the
* previous element emitted, using the specified effectual function to
* determine whether two elements are equal.
*
* @since 2.0.0
* @category utils
*/
const changesWithEffect = exports.changesWithEffect = internal.changesWithEffect;
/**
* Exposes the underlying chunks of the stream as a stream of chunks of
* elements.
*
* @since 2.0.0
* @category utils
*/
const chunks = exports.chunks = internal.chunks;
/**
* Performs the specified stream transformation with the chunk structure of
* the stream exposed.
*
* @since 2.0.0
* @category utils
*/
const chunksWith = exports.chunksWith = internal.chunksWith;
/**
* Combines the elements from this stream and the specified stream by
* repeatedly applying the function `f` to extract an element using both sides
* and conceptually "offer" it to the destination stream. `f` can maintain
* some internal state to control the combining process, with the initial
* state being specified by `s`.
*
* Where possible, prefer `Stream.combineChunks` for a more efficient
* implementation.
*
* @since 2.0.0
* @category utils
*/
const combine = exports.combine = internal.combine;
/**
* Combines the chunks from this stream and the specified stream by repeatedly
* applying the function `f` to extract a chunk using both sides and
* conceptually "offer" it to the destination stream. `f` can maintain some
* internal state to control the combining process, with the initial state
* being specified by `s`.
*
* @since 2.0.0
* @category utils
*/
const combineChunks = exports.combineChunks = internal.combineChunks;
/**
* Concatenates the specified stream with this stream, resulting in a stream
* that emits the elements from this stream and then the elements from the
* specified stream.
*
* @since 2.0.0
* @category utils
*/
const concat = exports.concat = internal.concat;
/**
* Concatenates all of the streams in the chunk to one stream.
*
* @since 2.0.0
* @category constructors
*/
const concatAll = exports.concatAll = internal.concatAll;
/**
* Composes this stream with the specified stream to create a cartesian
* product of elements. The `that` stream would be run multiple times, for
* every element in the `this` stream.
*
* See also `Stream.zip` for the more common point-wise variant.
*
* @since 2.0.0
* @category utils
*/
const cross = exports.cross = internal.cross;
/**
* Composes this stream with the specified stream to create a cartesian
* product of elements, but keeps only elements from this stream. The `that`
* stream would be run multiple times, for every element in the `this` stream.
*
* See also `Stream.zipLeft` for the more common point-wise variant.
*
* @since 2.0.0
* @category utils
*/
const crossLeft = exports.crossLeft = internal.crossLeft;
/**
* Composes this stream with the specified stream to create a cartesian
* product of elements, but keeps only elements from the other stream. The
* `that` stream would be run multiple times, for every element in the `this`
* stream.
*
* See also `Stream.zipRight` for the more common point-wise variant.
*
* @since 2.0.0
* @category utils
*/
const crossRight = exports.crossRight = internal.crossRight;
/**
* Composes this stream with the specified stream to create a cartesian
* product of elements with a specified function. The `that` stream would be
* run multiple times, for every element in the `this` stream.
*
* See also `Stream.zipWith` for the more common point-wise variant.
*
* @since 2.0.0
* @category utils
*/
const crossWith = exports.crossWith = internal.crossWith;
/**
* Delays the emission of values by holding new values for a set duration. If
* no new values arrive during that time the value is emitted, however if a
* new value is received during the holding period the previous value is
* discarded and the process is repeated with the new value.
*
* This operator is useful if you have a stream of "bursty" events which
* eventually settle down and you only need the final event of the burst. For
* example, a search engine may only want to initiate a search after a user
* has paused typing so as to not prematurely recommend results.
*
* @since 2.0.0
* @category utils
*/
const debounce = exports.debounce = internal.debounce;
/**
* The stream that dies with the specified defect.
*
* @since 2.0.0
* @category constructors
*/
const die = exports.die = internal.die;
/**
* The stream that dies with the specified lazily evaluated defect.
*
* @since 2.0.0
* @category constructors
*/
const dieSync = exports.dieSync = internal.dieSync;
/**
* The stream that dies with an exception described by `message`.
*
* @since 2.0.0
* @category constructors
*/
const dieMessage = exports.dieMessage = internal.dieMessage;
/**
* More powerful version of `Stream.broadcast`. Allows to provide a function
* that determines what queues should receive which elements. The decide
* function will receive the indices of the queues in the resulting list.
*
* @since 2.0.0
* @category utils
*/
const distributedWith = exports.distributedWith = internal.distributedWith;
/**
* More powerful version of `Stream.distributedWith`. This returns a function
* that will produce new queues and corresponding indices. You can also
* provide a function that will be executed after the final events are
* enqueued in all queues. Shutdown of the queues is handled by the driver.
* Downstream users can also shutdown queues manually. In this case the driver
* will continue but no longer backpressure on them.
*
* @since 2.0.0
* @category utils
*/
const distributedWithDynamic = exports.distributedWithDynamic = internal.distributedWithDynamic;
/**
* Converts this stream to a stream that executes its effects but emits no
* elements. Useful for sequencing effects using streams:
*
* @since 2.0.0
* @category utils
*/
const drain = exports.drain = internal.drain;
/**
* Drains the provided stream in the background for as long as this stream is
* running. If this stream ends before `other`, `other` will be interrupted.
* If `other` fails, this stream will fail with that error.
*
* @since 2.0.0
* @category utils
*/
const drainFork = exports.drainFork = internal.drainFork;
/**
* Drops the specified number of elements from this stream.
*
* @since 2.0.0
* @category utils
*/
const drop = exports.drop = internal.drop;
/**
* Drops the last specified number of elements from this stream.
*
* @note This combinator keeps `n` elements in memory. Be careful with big
* numbers.
* @since 2.0.0
* @category utils
*/
const dropRight = exports.dropRight = internal.dropRight;
/**
* Drops all elements of the stream until the specified predicate evaluates to
* `true`.
*
* @since 2.0.0
* @category utils
*/
const dropUntil = exports.dropUntil = internal.dropUntil;
/**
* Drops all elements of the stream until the specified effectful predicate
* evaluates to `true`.
*
* @since 2.0.0
* @category utils
*/
const dropUntilEffect = exports.dropUntilEffect = internal.dropUntilEffect;
/**
* Drops all elements of the stream for as long as the specified predicate
* evaluates to `true`.
*
* @since 2.0.0
* @category utils
*/
const dropWhile = exports.dropWhile = internal.dropWhile;
/**
* Drops all elements of the stream for as long as the specified predicate
* produces an effect that evalutates to `true`
*
* @since 2.0.0
* @category utils
*/
const dropWhileEffect = exports.dropWhileEffect = internal.dropWhileEffect;
/**
* Returns a stream whose failures and successes have been lifted into an
* `Either`. The resulting stream cannot fail, because the failures have been
* exposed as part of the `Either` success case.
*
* @note The stream will end as soon as the first error occurs.
*
* @since 2.0.0
* @category utils
*/
const either = exports.either = internal.either;
/**
* The empty stream.
*
* @since 2.0.0
* @category constructors
*/
const empty = exports.empty = internal.empty;
/**
* Executes the provided finalizer after this stream's finalizers run.
*
* @since 2.0.0
* @category utils
*/
const ensuring = exports.ensuring = internal.ensuring;
/**
* Executes the provided finalizer after this stream's finalizers run.
*
* @since 2.0.0
* @category utils
*/
const ensuringWith = exports.ensuringWith = internal.ensuringWith;
/**
* Accesses the whole context of the stream.
*
* @since 2.0.0
* @category context
*/
const context = exports.context = internal.context;
/**
* Accesses the context of the stream.
*
* @since 2.0.0
* @category context
*/
const contextWith = exports.contextWith = internal.contextWith;
/**
* Accesses the context of the stream in the context of an effect.
*
* @since 2.0.0
* @category context
*/
const contextWithEffect = exports.contextWithEffect = internal.contextWithEffect;
/**
* Accesses the context of the stream in the context of a stream.
*
* @since 2.0.0
* @category context
*/
const contextWithStream = exports.contextWithStream = internal.contextWithStream;
/**
* Creates a stream that executes the specified effect but emits no elements.
*
* @since 2.0.0
* @category constructors
*/
const execute = exports.execute = internal.execute;
/**
* Terminates with the specified error.
*
* @since 2.0.0
* @category constructors
*/
const fail = exports.fail = internal.fail;
/**
* Terminates with the specified lazily evaluated error.
*
* @since 2.0.0
* @category constructors
*/
const failSync = exports.failSync = internal.failSync;
/**
* The stream that always fails with the specified `Cause`.
*
* @since 2.0.0
* @category constructors
*/
const failCause = exports.failCause = internal.failCause;
/**
* The stream that always fails with the specified lazily evaluated `Cause`.
*
* @since 2.0.0
* @category constructors
*/
const failCauseSync = exports.failCauseSync = internal.failCauseSync;
/**
* Filters the elements emitted by this stream using the provided function.
*
* @since 2.0.0
* @category filtering
*/
const filter = exports.filter = internal.filter;
/**
* Effectfully filters the elements emitted by this stream.
*
* @since 2.0.0
* @category filtering
*/
const filterEffect = exports.filterEffect = internal.filterEffect;
/**
* Performs a filter and map in a single step.
*
* @since 2.0.0
* @category utils
*/
const filterMap = exports.filterMap = internal.filterMap;
/**
* Performs an effectful filter and map in a single step.
*
* @since 2.0.0
* @category utils
*/
const filterMapEffect = exports.filterMapEffect = internal.filterMapEffect;
/**
* Transforms all elements of the stream for as long as the specified partial
* function is defined.
*
* @since 2.0.0
* @category utils
*/
const filterMapWhile = exports.filterMapWhile = internal.filterMapWhile;
/**
* Effectfully transforms all elements of the stream for as long as the
* specified partial function is defined.
*
* @since 2.0.0
* @category utils
*/
const filterMapWhileEffect = exports.filterMapWhileEffect = internal.filterMapWhileEffect;
/**
* Creates a one-element stream that never fails and executes the finalizer
* when it ends.
*
* @since 2.0.0
* @category constructors
*/
const finalizer = exports.finalizer = internal.finalizer;
/**
* Finds the first element emitted by this stream that satisfies the provided
* predicate.
*
* @since 2.0.0
* @category elements
*/
const find = exports.find = internal.find;
/**
* Finds the first element emitted by this stream that satisfies the provided
* effectful predicate.
*
* @since 2.0.0
* @category elements
*/
const findEffect = exports.findEffect = internal.findEffect;
/**
* Returns a stream made of the concatenation in strict order of all the
* streams produced by passing each element of this stream to `f0`
*
* @since 2.0.0
* @category sequencing
*/
const flatMap = exports.flatMap = internal.flatMap;
/**
* Flattens this stream-of-streams into a stream made of the concatenation in
* strict order of all the streams.
*
* @since 2.0.0
* @category sequencing
*/
const flatten = exports.flatten = internal.flatten;
/**
* Submerges the chunks carried by this stream into the stream's structure,
* while still preserving them.
*
* @since 2.0.0
* @category sequencing
*/
const flattenChunks = exports.flattenChunks = internal.flattenChunks;
/**
* Flattens `Effect` values into the stream's structure, preserving all
* information about the effect.
*
* @since 2.0.0
* @category sequencing
*/
const flattenEffect = exports.flattenEffect = internal.flattenEffect;
/**
* Unwraps `Exit` values that also signify end-of-stream by failing with `None`.
*
* For `Exit` values that do not signal end-of-stream, prefer:
*
* ```ts
* stream.mapZIO(ZIO.done(_))
* ```
*
* @since 2.0.0
* @category sequencing
*/
const flattenExitOption = exports.flattenExitOption = internal.flattenExitOption;
/**
* Submerges the iterables carried by this stream into the stream's structure,
* while still preserving them.
*
* @since 2.0.0
* @category sequencing
*/
const flattenIterables = exports.flattenIterables = internal.flattenIterables;
/**
* Unwraps `Exit` values and flatten chunks that also signify end-of-stream
* by failing with `None`.
*
* @since 2.0.0
* @category sequencing
*/
const flattenTake = exports.flattenTake = internal.flattenTake;
/**
* Repeats this stream forever.
*
* @since 2.0.0
* @category utils
*/
const forever = exports.forever = internal.forever;
/**
* Creates a stream from an `AsyncIterable`.
*
* @since 2.0.0
* @category constructors
*/
const fromAsyncIterable = exports.fromAsyncIterable = internal.fromAsyncIterable;
/**
* Creates a stream from a `Channel`.
*
* @since 2.0.0
* @category constructors
*/
const fromChannel = exports.fromChannel = internal.fromChannel;
/**
* Creates a channel from a `Stream`.
*
* @since 2.0.0
* @category constructors
*/
const toChannel = exports.toChannel = internal.toChannel;
/**
* Creates a stream from a `Chunk` of values.
*
* @since 2.0.0
* @category constructors
*/
const fromChunk = exports.fromChunk = internal.fromChunk;
/**
* Creates a stream from a subscription to a `PubSub`.
*
* @param shutdown If `true`, the `PubSub` will be shutdown after the stream is evaluated (defaults to `false`)
* @since 2.0.0
* @category constructors
*/
const fromChunkPubSub = exports.fromChunkPubSub = internal.fromChunkPubSub;
/**
* Creates a stream from a `Queue` of values.
*
* @param shutdown If `true`, the queue will be shutdown after the stream is evaluated (defaults to `false`)
* @since 2.0.0
* @category constructors
*/
const fromChunkQueue = exports.fromChunkQueue = internal.fromChunkQueue;
/**
* Creates a stream from an arbitrary number of chunks.
*
* @since 2.0.0
* @category constructors
*/
const fromChunks = exports.fromChunks = internal.fromChunks;
/**
* Either emits the success value of this effect or terminates the stream
* with the failure value of this effect.
*
* @since 2.0.0
* @category constructors
*/
const fromEffect = exports.fromEffect = internal.fromEffect;
/**
* Creates a stream from an effect producing a value of type `A` or an empty
* `Stream`.
*
* @since 2.0.0
* @category constructors
*/
const fromEffectOption = exports.fromEffectOption = internal.fromEffectOption;
/**
* Creates a stream from a subscription to a `PubSub`.
*
* @param shutdown If `true`, the `PubSub` will be shutdown after the stream is evaluated (defaults to `false`)
* @since 2.0.0
* @category constructors
*/
const fromPubSub = exports.fromPubSub = internal.fromPubSub;
/**
* Creates a new `Stream` from an iterable collection of values.
*
* @since 2.0.0
* @category constructors
*/
const fromIterable = exports.fromIterable = internal.fromIterable;
/**
* Creates a stream from an effect producing a value of type `Iterable<A>`.
*
* @since 2.0.0
* @category constructors
*/
const fromIterableEffect = exports.fromIterableEffect = internal.fromIterableEffect;
/**
* Creates a stream from an iterator
*
* @since 2.0.0
* @category constructors
*/
const fromIteratorSucceed = exports.fromIteratorSucceed = internal.fromIteratorSucceed;
/**
* Creates a stream from an effect that pulls elements from another stream.
*
* See `Stream.toPull` for reference.
*
* @since 2.0.0
* @category constructors
*/
const fromPull = exports.fromPull = internal.fromPull;
/**
* Creates a stream from a queue of values
*
* @param maxChunkSize The maximum number of queued elements to put in one chunk in the stream
* @param shutdown If `true`, the queue will be shutdown after the stream is evaluated (defaults to `false`)
* @since 2.0.0
* @category constructors
*/
const fromQueue = exports.fromQueue = internal.fromQueue;
/**
* Creates a stream from a `ReadableStream`.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream.
*
* @since 2.0.0
* @category constructors
*/
const fromReadableStream = exports.fromReadableStream = internal.fromReadableStream;
/**
* Creates a stream from a `ReadableStreamBYOBReader`.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader.
*
* @param allocSize Controls the size of the underlying `ArrayBuffer` (defaults to `4096`).
* @since 2.0.0
* @category constructors
*/
const fromReadableStreamByob = exports.fromReadableStreamByob = internal.fromReadableStreamByob;
/**
* Creates a stream from a `Schedule` that does not require any further
* input. The stream will emit an element for each value output from the
* schedule, continuing for as long as the schedule continues.
*
* @since 2.0.0
* @category constructors
*/
const fromSchedule = exports.fromSchedule = internal.fromSchedule;
/**
* Creates a pipeline that groups on adjacent keys, calculated by the
* specified function.
*
* @since 2.0.0
* @category grouping
*/
const groupAdjacentBy = exports.groupAdjacentBy = internal.groupAdjacentBy;
/**
* More powerful version of `Stream.groupByKey`.
*
* @since 2.0.0
* @category grouping
*/
const groupBy = exports.groupBy = _groupBy.groupBy;
/**
* Partition a stream using a function and process each stream individually.
* This returns a data structure that can be used to further filter down which
* groups shall be processed.
*
* After calling apply on the GroupBy object, the remaining groups will be
* processed in parallel and the resulting streams merged in a
* nondeterministic fashion.
*
* Up to `buffer` elements may be buffered in any group stream before the
* producer is backpressured. Take care to consume from all streams in order
* to prevent deadlocks.
*
* For example, to collect the first 2 words for every starting letter from a
* stream of words:
*
* ```ts
* import * as GroupBy from "./GroupBy"
* import * as Stream from "./Stream"
* import { pipe } from "./Function"
*
* pipe(
* Stream.fromIterable(["hello", "world", "hi", "holla"]),
* Stream.groupByKey((word) => word[0]),
* GroupBy.evaluate((key, stream) =>
* pipe(
* stream,
* Stream.take(2),
* Stream.map((words) => [key, words] as const)
* )
* )
* )
* ```
*
* @since 2.0.0
* @category utils
*/
const groupByKey = exports.groupByKey = _groupBy.groupByKey;
/**
* Partitions the stream with specified `chunkSize`.
*
* @since 2.0.0
* @category utils
*/
const grouped = exports.grouped = internal.grouped;
/**
* Partitions the stream with the specified `chunkSize` or until the specified
* `duration` has passed, whichever is satisfied first.
*
* @since 2.0.0
* @category utils
*/
const groupedWithin = exports.groupedWithin = internal.groupedWithin;
/**
* Specialized version of haltWhen which halts the evaluation of this stream
* after the given duration.
*
* An element in the process of being pulled will not be interrupted when the
* given duration completes. See `interruptAfter` for this behavior.
*
* @since 2.0.0
* @category utils
*/
const haltAfter = exports.haltAfter = internal.haltAfter;
/**
* Halts the evaluation of this stream when the provided effect completes. The
* given effect will be forked as part of the returned stream, and its success
* will be discarded.
*
* An element in the process of being pulled will not be interrupted when the
* effect completes. See `interruptWhen` for this behavior.
*
* If the effect completes with a failure, the stream will emit that failure.
*
* @since 2.0.0
* @category utils
*/
const haltWhen = exports.haltWhen = internal.haltWhen;
/**
* Halts the evaluation of this stream when the provided promise resolves.
*
* If the promise completes with a failure, the stream will emit that failure.
*
* @since 2.0.0
* @category utils
*/
const haltWhenDeferred = exports.haltWhenDeferred = internal.haltWhenDeferred;
/**
* The identity pipeline, which does not modify streams in any way.
*
* @since 2.0.0
* @category utils
*/
const identity = exports.identity = internal.identityStream;
/**
* Interleaves this stream and the specified stream deterministically by
* alternating pulling values from this stream and the specified stream. When
* one stream is exhausted all remaining values in the other stream will be
* pulled.
*
* @since 2.0.0
* @category utils
*/
const interleave = exports.interleave = internal.interleave;
/**
* Combines this stream and the specified stream deterministically using the
* stream of boolean values `pull` to control which stream to pull from next.
* A value of `true` indicates to pull from this stream and a value of `false`
* indicates to pull from the specified stream. Only consumes as many elements
* as requested by the `pull` stream. If either this stream or the specified
* stream are exhausted further requests for values from that stream will be
* ignored.
*
* @since 2.0.0
* @category utils
*/
const interleaveWith = exports.interleaveWith = internal.interleaveWith;
/**
* Intersperse stream with provided `element`.
*
* @since 2.0.0
* @category utils
*/
const intersperse = exports.intersperse = internal.intersperse;
/**
* Intersperse the specified element, also adding a prefix and a suffix.
*
* @since 2.0.0
* @category utils
*/
const intersperseAffixes = exports.intersperseAffixes = internal.intersperseAffixes;
/**
* Specialized version of `Stream.interruptWhen` which interrupts the
* evaluation of this stream after the given `Duration`.
*
* @since 2.0.0
* @category utils
*/
const interruptAfter = exports.interruptAfter = internal.interruptAfter;
/**
* Interrupts the evaluation of this stream when the provided effect
* completes. The given effect will be forked as part of this stream, and its
* success will be discarded. This combinator will also interrupt any
* in-progress element being pulled from upstream.
*
* If the effect completes with a failure before the stream completes, the
* returned stream will emit that failure.
*
* @since 2.0.0
* @category utils
*/
const interruptWhen = exports.interruptWhen = internal.interruptWhen;
/**
* Interrupts the evaluation of this stream when the provided promise
* resolves. This combinator will also interrupt any in-progress element being
* pulled from upstream.
*
* If the promise completes with a failure, the stream will emit that failure.
*
* @since 2.0.0
* @category utils
*/
const interruptWhenDeferred = exports.interruptWhenDeferred = internal.interruptWhenDeferred;
/**
* The infinite stream of iterative function application: a, f(a), f(f(a)),
* f(f(f(a))), ...
*
* @since 2.0.0
* @category constructors
*/
const iterate = exports.iterate = internal.iterate;
/**
* Creates a stream from an sequence of values.
*
* @since 2.0.0
* @category constructors
*/
const make = exports.make = internal.make;
/**
* Transforms the elements of this stream using the supplied function.
*
* @since 2.0.0
* @category mapping
*/
const map = exports.map = internal.map;
/**
* Statefully maps over the elements of this stream to produce new elements.
*
* @since 2.0.0
* @category mapping
*/
const mapAccum = exports.mapAccum = internal.mapAccum;
/**
* Statefully and effectfully maps over the elements of this stream to produce
* new elements.
*
* @since 2.0.0
* @category mapping
*/
const mapAccumEffect = exports.mapAccumEffect = internal.mapAccumEffect;
/**
* Returns a stream whose failure and success channels have been mapped by the
* specified `onFailure` and `onSuccess` functions.
*
* @since 2.0.0
* @category utils
*/
const mapBoth = exports.mapBoth = internal.mapBoth;
/**
* Transforms the chunks emitted by this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapChunks = exports.mapChunks = internal.mapChunks;
/**
* Effectfully transforms the chunks emitted by this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapChunksEffect = exports.mapChunksEffect = internal.mapChunksEffect;
/**
* Maps each element to an iterable, and flattens the iterables into the
* output of this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapConcat = exports.mapConcat = internal.mapConcat;
/**
* Maps each element to a chunk, and flattens the chunks into the output of
* this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapConcatChunk = exports.mapConcatChunk = internal.mapConcatChunk;
/**
* Effectfully maps each element to a chunk, and flattens the chunks into the
* output of this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapConcatChunkEffect = exports.mapConcatChunkEffect = internal.mapConcatChunkEffect;
/**
* Effectfully maps each element to an iterable, and flattens the iterables
* into the output of this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapConcatEffect = exports.mapConcatEffect = internal.mapConcatEffect;
/**
* Maps over elements of the stream with the specified effectful function.
*
* @since 2.0.0
* @category mapping
*/
const mapEffect = exports.mapEffect = _groupBy.mapEffectOptions;
/**
* Transforms the errors emitted by this stream using `f`.
*
* @since 2.0.0
* @category mapping
*/
const mapError = exports.mapError = internal.mapError;
/**
* Transforms the full causes of failures emitted by this stream.
*
* @since 2.0.0
* @category mapping
*/
const mapErrorCause = exports.mapErrorCause = internal.mapErrorCause;
/**
* Merges this stream and the specified stream together.
*
* New produced stream will terminate when both specified stream terminate if
* no termination strategy is specified.
*
* @since 2.0.0
* @category utils
*/
const merge = exports.merge = internal.merge;
/**
* Merges a variable list of streams in a non-deterministic fashion. Up to `n`
* streams may be consumed in parallel and up to `outputBuffer` chunks may be
* buffered by this operator.
*
* @since 2.0.0
* @category utils
*/
const mergeAll = exports.mergeAll = internal.mergeAll;
/**
* Merges this stream and the specified stream together to a common element
* type with the specified mapping functions.
*
* New produced stream will terminate when both specified stream terminate if
* no termination strategy is specified.
*
* @since 2.0.0
* @category utils
*/
const mergeWith = exports.mergeWith = internal.mergeWith;
/**
* Merges this stream and the specified stream together to produce a stream of
* eithers.
*
* @since 2.0.0
* @category utils
*/
const mergeEither = exports.mergeEither = internal.mergeEither;
/**
* Merges this stream and the specified stream together, discarding the values
* from the right stream.
*
* @since 2.0.0
* @category utils
*/
const mergeLeft = exports.mergeLeft = internal.mergeLeft;
/**
* Merges this stream and the specified stream together, discarding the values
* from the left stream.
*
* @since 2.0.0
* @category utils
*/
const mergeRight = exports.mergeRight = internal.mergeRight;
/**
* Returns a combined string resulting from concatenating each of the values
* from the stream.
*
* @since 2.0.0
* @category utils
*/
const mkString = exports.mkString = internal.mkString;
/**
* The stream that never produces any value or fails with any error.
*
* @since 2.0.0
* @category constructors
*/
const never = exports.never = internal.never;
/**
* Runs the specified effect if this stream fails, providing the error to the
* effect if it exists.
*
* Note: Unlike `Effect.onError` there is no guarantee that the provided
* effect will not be interrupted.
*
* @since 2.0.0
* @category utils
*/
const onError = exports.onError = internal.onError;
/**
* Runs the specified effect if this stream ends.
*
* @since 2.0.0
* @category utils
*/
const onDone = exports.onDone = internal.onDone;
/**
* Translates any failure into a stream termination, making the stream
* infallible and all failures unchecked.
*
* @since 2.0.0
* @category error handling
*/
const orDie = exports.orDie = internal.orDie;
/**
* Keeps none of the errors, and terminates the stream with them, using the
* specified function to convert the `E` into a defect.
*
* @since 2.0.0
* @category error handling
*/
const orDieWith = exports.orDieWith = internal.orDieWith;
/**
* Switches to the provided stream in case this one fails with a typed error.
*
* See also `Stream.catchAll`.
*
* @since 2.0.0
* @category error handling
*/
const orElse = exports.orElse = internal.orElse;
/**
* Switches to the provided stream in case this one fails with a typed error.
*
* See also `Stream.catchAll`.
*
* @since 2.0.0
* @category error handling
*/
const orElseEither = exports.orElseEither = internal.orElseEither;
/**
* Fails with given error in case this one fails with a typed error.
*
* See also `Stream.catchAll`.
*
* @since 2.0.0
* @category error handling
*/
const orElseFail = exports.orElseFail = internal.orElseFail;
/**
* Produces the specified element if this stream is empty.
*
* @since 2.0.0
* @category error handling
*/
const orElseIfEmpty = exports.orElseIfEmpty = internal.orElseIfEmpty;
/**
* Produces the specified chunk if this stream is empty.
*
* @since 2.0.0
* @category error handling
*/
const orElseIfEmptyChunk = exports.orElseIfEmptyChunk = internal.orElseIfEmptyChunk;
/**
* Switches to the provided stream in case this one is empty.
*
* @since 2.0.0
* @category error handling
*/
const orElseIfEmptyStream = exports.orElseIfEmptyStream = internal.orElseIfEmptyStream;
/**
* Succeeds with the specified value if this one fails with a typed error.
*
* @since 2.0.0
* @category error handling
*/
const orElseSucceed = exports.orElseSucceed = internal.orElseSucceed;
/**
* Like `Stream.unfold`, but allows the emission of values to end one step further
* than the unfolding of the state. This is useful for embedding paginated
* APIs, hence the name.
*
* @since 2.0.0
* @category constructors
*/
const paginate = exports.paginate = internal.paginate;
/**
* Like `Stream.unfoldChunk`, but allows the emission of values to end one step
* further than the unfolding of the state. This is useful for embedding
* paginated APIs, hence the name.
*
* @since 2.0.0
* @category constructors
*/
const paginateChunk = exports.paginateChunk = internal.paginateChunk;
/**
* Like `Stream.unfoldChunkEffect`, but allows the emission of values to end one step
* further than the unfolding of the state. This is useful for embedding
* paginated APIs, hence the name.
*
* @since 2.0.0
* @category constructors
*/
const paginateChunkEffect = exports.paginateChunkEffect = internal.paginateChunkEffect;
/**
* Like `Stream.unfoldEffect` but allows the emission of values to end one step
* further than the unfolding of the state. This is useful for embedding
* paginated APIs, hence the name.
*
* @since 2.0.0
* @category constructors
*/
const paginateEffect = exports.paginateEffect = internal.paginateEffect;
/**
* Partition a stream using a predicate. The first stream will contain all
* element evaluated to true and the second one will contain all element
* evaluated to false. The faster stream may advance by up to buffer elements
* further than the slower one.
*
* @since 2.0.0
* @category utils
*/
const partition = exports.partition = internal.partition;
/**
* Split a stream by an effectful predicate. The faster stream may advance by
* up to buffer elements further than the slower one.
*
* @since 2.0.0
* @category utils
*/
const partitionEither = exports.partitionEither = internal.partitionEither;
/**
* Peels off enough material from the stream to construct a `Z` using the
* provided `Sink` and then returns both the `Z` and the rest of the
* `Stream` in a scope. Like all scoped values, the provided stream is
* valid only within the scope.
*
* @since 2.0.0
* @category utils
*/
const peel = exports.peel = internal.peel;
/**
* Pipes all of the values from this stream through the provided sink.
*
* See also `Stream.transduce`.
*
* @since 2.0.0
* @category utils
*/
const pipeThrough = exports.pipeThrough = internal.pipeThrough;
/**
* Pipes all the values from this stream through the provided channel.
*
* @since 2.0.0
* @category utils
*/
const pipeThroughChannel = exports.pipeThroughChannel = internal.pipeThroughChannel;
/**
* Pipes all values from this stream through the provided channel, passing
* through any error emitted by this stream unchanged.
*
* @since 2.0.0
* @category utils
*/
const pipeThroughChannelOrFail = exports.pipeThroughChannelOrFail = internal.pipeThroughChannelOrFail;
/**
* Emits the provided chunk before emitting any other value.
*
* @since 2.0.0
* @category utils
*/
const prepend = exports.prepend = internal.prepend;
/**
* Provides the stream with its required context, which eliminates its
* dependency on `R`.
*
* @since 2.0.0
* @category context
*/
const provideContext = exports.provideContext =