UNPKG

@codibre/fluent-iterable

Version:

Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).

32 lines (31 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addAsyncFluentResolvingMethod = exports.FluentAsyncClass = void 0; exports.addAsyncFluentMethod = addAsyncFluentMethod; const types_internal_1 = require("./types-internal"); const utils_1 = require("./utils"); const internal_utils_1 = require("./utils/internal-utils"); class FluentAsyncClass { constructor(base) { this.base = (0, utils_1.iterateAsync)(base); } [Symbol.asyncIterator]() { return this.base[Symbol.asyncIterator](); } get [types_internal_1.orderAssured]() { return this.base[types_internal_1.orderAssured]; } set [types_internal_1.orderAssured](value) { this.base[types_internal_1.orderAssured] = value; } } exports.FluentAsyncClass = FluentAsyncClass; function addAsyncFluentMethod(method, body) { if (FluentAsyncClass.prototype.hasOwnProperty(method)) { throw new TypeError(`Prototype already has a method called ${method}`); } FluentAsyncClass.prototype[method] = function (...args) { return new FluentAsyncClass((0, utils_1.iterateAsync)(body.apply(this['base'], args))); }; } exports.addAsyncFluentResolvingMethod = (0, internal_utils_1.addFluentResolvingFactory)(FluentAsyncClass);