fluent-iterable
Version:
Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).
79 lines • 5.99 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fluentAsync_1 = __importDefault(require("./fluentAsync"));
const utils_1 = require("./utils");
const fluentFunctions_1 = require("./fluentFunctions");
/**
* Tranforms an iterable into a [[FluentIterable]].
* @typeparam T The type of the items in the iterable.
* @param iterable The iterable instance.
* @returns The [[FluentIterable]] instance.
*/
function fluent(iterable) {
return {
withIndex: () => fluent(fluentFunctions_1.withIndex(iterable)),
takeWhile: predicate => fluent(fluentFunctions_1.takeWhile(iterable, predicate)),
takeWhileAsync: predicate => fluentAsync_1.default(fluentFunctions_1.takeWhileAsync(iterable, predicate)),
take: n => fluent(fluentFunctions_1.take(iterable, n)),
skipWhile: predicate => fluent(fluentFunctions_1.skipWhile(iterable, predicate)),
skipWhileAsync: predicate => fluentAsync_1.default(fluentFunctions_1.skipWhileAsync(iterable, predicate)),
skip: n => fluent(fluentFunctions_1.skip(iterable, n)),
map: mapper => fluent(fluentFunctions_1.map(iterable, mapper)),
mapAsync: mapper => fluentAsync_1.default(fluentFunctions_1.mapAsync(iterable, mapper)),
filter: predicate => fluent(fluentFunctions_1.filter(iterable, predicate)),
filterAsync: predicate => fluentAsync_1.default(fluentFunctions_1.filterAsync(iterable, predicate)),
partition: size => fluent(fluentFunctions_1.partition(iterable, size)).map(part => fluent(part)),
append: item => fluent(fluentFunctions_1.append(iterable, item)),
prepend: item => fluent(fluentFunctions_1.prepend(iterable, item)),
concat: (...iterables) => fluent(fluentFunctions_1.concat(iterable, ...iterables)),
repeat: n => fluent(fluentFunctions_1.repeat(iterable, n)),
flatten: (mapper = utils_1.identity) => fluent(fluentFunctions_1.flatten(iterable, mapper)),
flattenAsync: mapper => fluentAsync_1.default(fluentFunctions_1.flattenAsync(iterable, mapper)),
sort: (comparer) => fluent(fluentFunctions_1.sort(iterable, comparer)),
distinct: (mapper = utils_1.identity) => fluent(fluentFunctions_1.distinct(iterable, mapper)),
distinctAsync: mapper => fluentAsync_1.default(fluentFunctions_1.distinctAsync(iterable, mapper)),
group: (mapper) => fluent(fluentFunctions_1.group(iterable, mapper)).map(utils_1.fluentGroup),
groupAsync: mapper => fluentAsync_1.default(fluentFunctions_1.groupAsync(iterable, mapper)).map(utils_1.fluentGroup),
count: (predicate = utils_1.truth) => fluentFunctions_1.count(iterable, predicate),
countAsync: predicate => fluentFunctions_1.countAsync(iterable, predicate),
first: (predicate = utils_1.truth) => fluentFunctions_1.first(iterable, predicate),
firstAsync: predicate => fluentFunctions_1.firstAsync(iterable, predicate),
last: (predicate = utils_1.truth) => fluentFunctions_1.last(iterable, predicate),
lastAsync: predicate => fluentFunctions_1.lastAsync(iterable, predicate),
reduceAndMap: (reducer, initial, result) => fluentFunctions_1.reduceAndMap(iterable, reducer, initial, result),
reduceAndMapAsync: (reducer, initial, result) => fluentFunctions_1.reduceAndMapAsync(iterable, reducer, initial, result),
reduce: (reducer, initial) => fluentFunctions_1.reduce(iterable, reducer, initial),
reduceAsync: (reducer, initial) => fluentFunctions_1.reduceAsync(iterable, reducer, initial),
all: predicate => fluentFunctions_1.all(iterable, predicate),
allAsync: predicate => fluentFunctions_1.allAsync(iterable, predicate),
any: (predicate = utils_1.truth) => fluentFunctions_1.any(iterable, predicate),
anyAsync: predicate => fluentFunctions_1.anyAsync(iterable, predicate),
contains: item => fluentFunctions_1.contains(iterable, item),
toArray: () => fluentFunctions_1.toArray(iterable),
toObject: (keySelector, valueSelector = utils_1.identity) => fluentFunctions_1.toObject(iterable, keySelector, valueSelector),
toObjectAsync: (keySelector, valueSelector) => fluentFunctions_1.toObjectAsync(iterable, keySelector, valueSelector),
toAsync: () => fluentAsync_1.default(fluentFunctions_1.toAsync(iterable)),
forEach: action => fluentFunctions_1.forEach(iterable, action),
forEachAsync: action => fluentFunctions_1.forEachAsync(iterable, action),
execute: action => fluent(fluentFunctions_1.execute(iterable, action)),
executeAsync: action => fluentAsync_1.default(fluentFunctions_1.executeAsync(iterable, action)),
join: (separator, mapper = utils_1.identity) => fluentFunctions_1.join(iterable, separator, mapper),
joinAsync: (separator, mapper) => fluentFunctions_1.joinAsync(iterable, separator, mapper),
sum: (mapper = utils_1.identity) => fluentFunctions_1.sum(iterable, mapper),
sumAsync: mapper => fluentFunctions_1.sumAsync(iterable, mapper),
avg: (mapper = utils_1.identity) => fluentFunctions_1.avg(iterable, mapper),
avgAsync: mapper => fluentFunctions_1.avgAsync(iterable, mapper),
top: (mapper, comparer) => fluentFunctions_1.top(iterable, mapper, comparer),
topAsync: (mapper, comparer) => fluentFunctions_1.topAsync(iterable, mapper, comparer),
min: (mapper = utils_1.identity) => fluentFunctions_1.min(iterable, mapper),
minAsync: mapper => fluentFunctions_1.minAsync(iterable, mapper),
max: (mapper = utils_1.identity) => fluentFunctions_1.max(iterable, mapper),
maxAsync: mapper => fluentFunctions_1.maxAsync(iterable, mapper),
[Symbol.iterator]: () => iterable[Symbol.iterator](),
};
}
exports.default = fluent;
//# sourceMappingURL=fluent.js.map