fast-iterable
Version:
Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).
49 lines (48 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fluentEmit = exports.fluentAsync = void 0;
const mounters_1 = require("./mounters");
const mounters_2 = require("./mounters");
const utils_1 = require("./utils");
const extension_methods_1 = require("extension-methods");
const emitter_1 = require("./emitter");
const types_internal_1 = require("./types-internal");
const async_handler_1 = require("./async-handler");
const internal_wrapper_1 = require("./internal-wrapper");
/**
* Tranforms an asynchronous iterable into a [[FluentAsyncIterable]].
* @typeparam T The type of the items in the async iterable.
* @param iterable The asynchronous iterable instance.
* @returns The [[FluentAsyncIterable]] instance.
*/
function fluentAsync(iterable) {
return (0, types_internal_1.getFluent)((0, utils_1.iterateAsync)(iterable), async_handler_1.asyncHandler, types_internal_1.fluentSymbolAsync);
}
exports.fluentAsync = fluentAsync;
/**
* Transforms an EventEmitter into a [[FluentAsyncIterable]].
*
*
* **IMPORTANT**: the AsyncIterable created from the EventEmitter is always based on a key event which every
* emission generates a new yielded result. The default key event is **'data'**.
*
* Also, the generated AsyncIterable will be infinite unless an ending event is emitted at some point.
* The defaults ending events are **'end'** and **'close'**. So, it's important to have in mind this behavior
* to use this feature properly. Operations that requires finiteness to be used may fall into an infinite loop.
*
* If you need to change the key event or other characteristics, you can do it through the **options** parameter
* @typeparam T The type of the items in the created FluentAsyncIterable.
* @param emitter The EventEmitter
* @param options The EventEmitter options. Optional
* @returns The [[FluentAsyncIterable]] instance.
*/
function fluentEmit(emitter, options) {
return (0, extension_methods_1.extend)((0, emitter_1.getIterableFromEmitter)(emitter, options), async_handler_1.asyncHandler);
}
exports.fluentEmit = fluentEmit;
Object.assign(async_handler_1.asyncProxyReference, {
...(0, mounters_2.mountIterableFunctions)(mounters_1.asyncIterableFuncs, internal_wrapper_1.internalAsyncWrapper),
...(0, mounters_2.mountSpecial)(mounters_1.asyncSpecial, internal_wrapper_1.internalAsyncWrapper, internal_wrapper_1.internalAsyncWrapper),
...mounters_1.asyncResolvingFuncs,
fluent: types_internal_1.fluentSymbolAsync,
});