UNPKG

fluent-iterable

Version:

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

74 lines 6.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fluentAsyncFunctions_1 = require("./fluentAsyncFunctions"); const utils_1 = require("./utils"); /** * 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 { withIndex: () => fluentAsync(fluentAsyncFunctions_1.withIndex(iterable)), takeWhile: predicate => fluentAsync(fluentAsyncFunctions_1.takeWhile(iterable, predicate)), takeWhileAsync: predicate => fluentAsync(fluentAsyncFunctions_1.takeWhileAsync(iterable, predicate)), take: n => fluentAsync(fluentAsyncFunctions_1.take(iterable, n)), skipWhile: predicate => fluentAsync(fluentAsyncFunctions_1.skipWhile(iterable, predicate)), skipWhileAsync: predicate => fluentAsync(fluentAsyncFunctions_1.skipWhileAsync(iterable, predicate)), skip: n => fluentAsync(fluentAsyncFunctions_1.skip(iterable, n)), map: mapper => fluentAsync(fluentAsyncFunctions_1.map(iterable, mapper)), mapAsync: mapper => fluentAsync(fluentAsyncFunctions_1.mapAsync(iterable, mapper)), filter: predicate => fluentAsync(fluentAsyncFunctions_1.filter(iterable, predicate)), filterAsync: predicate => fluentAsync(fluentAsyncFunctions_1.filterAsync(iterable, predicate)), partition: size => fluentAsync(fluentAsyncFunctions_1.partition(iterable, size)).map(part => fluentAsync(part)), append: item => fluentAsync(fluentAsyncFunctions_1.append(iterable, item)), prepend: item => fluentAsync(fluentAsyncFunctions_1.prepend(iterable, item)), concat: (...iterables) => fluentAsync(fluentAsyncFunctions_1.concat(iterable, ...iterables)), repeat: n => fluentAsync(fluentAsyncFunctions_1.repeat(iterable, n)), flatten: (mapper = utils_1.identity) => fluentAsync(fluentAsyncFunctions_1.flatten(iterable, mapper)), flattenAsync: mapper => fluentAsync(fluentAsyncFunctions_1.flattenAsync(iterable, mapper)), sort: (comparer) => fluentAsync(fluentAsyncFunctions_1.sort(iterable, comparer)), distinct: (mapper = utils_1.identity) => fluentAsync(fluentAsyncFunctions_1.distinct(iterable, mapper)), distinctAsync: mapper => fluentAsync(fluentAsyncFunctions_1.distinctAsync(iterable, mapper)), group: (mapper) => fluentAsync(fluentAsyncFunctions_1.group(iterable, mapper)).map(utils_1.fluentGroup), groupAsync: mapper => fluentAsync(fluentAsyncFunctions_1.groupAsync(iterable, mapper)).map(utils_1.fluentGroup), count: (predicate = utils_1.truth) => fluentAsyncFunctions_1.count(iterable, predicate), countAsync: (predicate) => fluentAsyncFunctions_1.countAsync(iterable, predicate), first: (predicate = utils_1.truth) => fluentAsyncFunctions_1.first(iterable, predicate), firstAsync: predicate => fluentAsyncFunctions_1.firstAsync(iterable, predicate), last: (predicate = utils_1.truth) => fluentAsyncFunctions_1.last(iterable, predicate), lastAsync: predicate => fluentAsyncFunctions_1.lastAsync(iterable, predicate), reduceAndMap: (reducer, initial, result) => fluentAsyncFunctions_1.reduceAndMap(iterable, reducer, initial, result), reduceAndMapAsync: (reducer, initial, result) => fluentAsyncFunctions_1.reduceAndMapAsync(iterable, reducer, initial, result), reduce: (reducer, initial) => fluentAsyncFunctions_1.reduce(iterable, reducer, initial), reduceAsync: (reducer, initial) => fluentAsyncFunctions_1.reduceAsync(iterable, reducer, initial), all: predicate => fluentAsyncFunctions_1.all(iterable, predicate), allAsync: predicate => fluentAsyncFunctions_1.allAsync(iterable, predicate), any: (predicate = utils_1.truth) => fluentAsyncFunctions_1.any(iterable, predicate), anyAsync: predicate => fluentAsyncFunctions_1.anyAsync(iterable, predicate), contains: item => fluentAsyncFunctions_1.contains(iterable, item), toArray: () => fluentAsyncFunctions_1.toArray(iterable), toObject: (keySelector, valueSelector = utils_1.identity) => fluentAsyncFunctions_1.toObject(iterable, keySelector, valueSelector), toObjectAsync: (keySelector, valueSelector) => fluentAsyncFunctions_1.toObjectAsync(iterable, keySelector, valueSelector), forEach: action => fluentAsyncFunctions_1.forEach(iterable, action), forEachAsync: action => fluentAsyncFunctions_1.forEachAsync(iterable, action), execute: action => fluentAsync(fluentAsyncFunctions_1.execute(iterable, action)), executeAsync: action => fluentAsync(fluentAsyncFunctions_1.executeAsync(iterable, action)), join: (separator, mapper = utils_1.identity) => fluentAsyncFunctions_1.join(iterable, separator, mapper), joinAsync: (separator, mapper) => fluentAsyncFunctions_1.joinAsync(iterable, separator, mapper), sum: (mapper = utils_1.identity) => fluentAsyncFunctions_1.sum(iterable, mapper), sumAsync: mapper => fluentAsyncFunctions_1.sumAsync(iterable, mapper), avg: (mapper = utils_1.identity) => fluentAsyncFunctions_1.avg(iterable, mapper), avgAsync: mapper => fluentAsyncFunctions_1.avgAsync(iterable, mapper), top: (mapper, comparer) => fluentAsyncFunctions_1.top(iterable, mapper, comparer), topAsync: (mapper, comparer) => fluentAsyncFunctions_1.topAsync(iterable, mapper, comparer), min: (mapper = utils_1.identity) => fluentAsyncFunctions_1.min(iterable, mapper), minAsync: mapper => fluentAsyncFunctions_1.minAsync(iterable, mapper), max: (mapper = utils_1.identity) => fluentAsyncFunctions_1.max(iterable, mapper), maxAsync: mapper => fluentAsyncFunctions_1.maxAsync(iterable, mapper), [Symbol.asyncIterator]: () => iterable[Symbol.asyncIterator](), }; } exports.default = fluentAsync; //# sourceMappingURL=fluentAsync.js.map