Comparing version 1.1.1 to 1.1.2
@@ -58,2 +58,6 @@ "use strict"; | ||
}; | ||
function tupleMap(tuple, f) { | ||
return tuple.map(f); | ||
} | ||
var r = tupleMap([1, 2, 3, 4], function (v) { return String(v); }); | ||
var Collector; | ||
@@ -99,86 +103,23 @@ (function (Collector) { | ||
* @typeparam A the input element type | ||
* @typeparam R the output type of the provided `col1` | ||
* @typeparam R2 the output type of the provided `col2` | ||
* @typeparam CR a tuple corresponding to the output types of the input collectors | ||
* @typeparam GR the result type of the `combineFun` function | ||
* @param combineFun a function that takes the tupled output of all provided collectors, and combines them into one result value | ||
* @param col1 a Collector taking the same type of elements | ||
* @param col2 a Collector taking the same type of elements | ||
* @param otherCollectors a number of Collectors taking the same type of elements | ||
* @param collectors a number of Collectors taking the same type of elements as input | ||
*/ | ||
function combineWith(combineFun, col1, col2) { | ||
var otherCollectors = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
otherCollectors[_i - 3] = arguments[_i]; | ||
function combineWith(combineFun) { | ||
var collectors = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
collectors[_i - 1] = arguments[_i]; | ||
} | ||
return createState({ | ||
init: function () { return __spread([ | ||
col1.createInitState(), | ||
col2.createInitState() | ||
], otherCollectors.map(function (col) { return col.createInitState(); })); }, | ||
next: function (_a, elem, index) { | ||
var _b = __read(_a), state1 = _b[0], state2 = _b[1], otherStates = _b.slice(2); | ||
var e_1, _c; | ||
var newStates = [col1.nextState(state1, elem, index), col2.nextState(state2, elem, index)]; | ||
var i = 0; | ||
try { | ||
for (var otherStates_1 = __values(otherStates), otherStates_1_1 = otherStates_1.next(); !otherStates_1_1.done; otherStates_1_1 = otherStates_1.next()) { | ||
var state = otherStates_1_1.value; | ||
newStates.push(otherCollectors[i].nextState(state, elem, index)); | ||
i++; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (otherStates_1_1 && !otherStates_1_1.done && (_c = otherStates_1.return)) _c.call(otherStates_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return newStates; | ||
init: function () { return collectors.map(function (col) { return col.createInitState(); }); }, | ||
next: function (states, elem, index) { | ||
return states.map(function (state, i) { return collectors[i].nextState(state, elem, index); }); | ||
}, | ||
stateToResult: function (_a, index) { | ||
var _b = __read(_a), state1 = _b[0], state2 = _b[1], otherStates = _b.slice(2); | ||
var e_2, _c; | ||
var results = []; | ||
var i = 0; | ||
try { | ||
for (var otherStates_2 = __values(otherStates), otherStates_2_1 = otherStates_2.next(); !otherStates_2_1.done; otherStates_2_1 = otherStates_2.next()) { | ||
var state = otherStates_2_1.value; | ||
results.push(otherCollectors[i].stateToResult(state, index)); | ||
i++; | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (otherStates_2_1 && !otherStates_2_1.done && (_c = otherStates_2.return)) _c.call(otherStates_2); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return combineFun.apply(void 0, __spread([col1.stateToResult(state1, index), | ||
col2.stateToResult(state2, index)], results)); | ||
stateToResult: function (states, size) { | ||
var results = states.map(function (state, i) { return collectors[i].stateToResult(state, size); }); | ||
return combineFun.apply(void 0, __spread(results)); | ||
}, | ||
escape: function (_a, index) { | ||
var _b = __read(_a), state1 = _b[0], state2 = _b[1], otherStates = _b.slice(2); | ||
var e_3, _c; | ||
var esc = iternal_common_1.optPred(state1, index, col1.escape) && iternal_common_1.optPred(state2, index, col2.escape); | ||
if (esc) | ||
return true; | ||
var i = 0; | ||
try { | ||
for (var otherStates_3 = __values(otherStates), otherStates_3_1 = otherStates_3.next(); !otherStates_3_1.done; otherStates_3_1 = otherStates_3.next()) { | ||
var state = otherStates_3_1.value; | ||
if (iternal_common_1.optPred(state, index, otherCollectors[i].escape)) | ||
return true; | ||
i++; | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (otherStates_3_1 && !otherStates_3_1.done && (_c = otherStates_3.return)) _c.call(otherStates_3); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return false; | ||
escape: function (states, index) { | ||
return states.every(function (state, i) { return iternal_common_1.optPred(state, index, collectors[i].escape); }); | ||
} | ||
@@ -191,14 +132,10 @@ }); | ||
* The results are collected into an array. | ||
* Note: due to type system limitations only the type of the first other collector is kept | ||
* @typeparam A the input element type | ||
* @typeparam R the output type of the provided `col1` | ||
* @typeparam R2 the output type of the provided `col2` | ||
* @param col1 a Collector taking the same type of elements | ||
* @param col2 a Collector taking the same type of elements | ||
* @param otherCollectors a number of Collectors taking the same type of elements | ||
* @typeparam CR a tuple corresponding to the output types of the input collectors | ||
* @param collectors a number of Collectors taking the same type of elements as input | ||
*/ | ||
function combine(col1, col2) { | ||
var otherCollectors = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
otherCollectors[_i - 2] = arguments[_i]; | ||
function combine() { | ||
var collectors = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
collectors[_i] = arguments[_i]; | ||
} | ||
@@ -211,3 +148,3 @@ return combineWith.apply(void 0, __spread([function () { | ||
return results; | ||
}, col1, col2], otherCollectors)); | ||
}], collectors)); | ||
} | ||
@@ -347,3 +284,3 @@ Collector.combine = combine; | ||
return new StateCollector(__assign({}, this.definition, { createInitState: function () { | ||
var e_4, _a; | ||
var e_1, _a; | ||
var state = _this.createInitState(); | ||
@@ -358,3 +295,3 @@ var index = 0; | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
@@ -364,3 +301,3 @@ try { | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
@@ -383,3 +320,3 @@ return state; | ||
return new StateCollector(__assign({}, this.definition, { stateToResult: function (state, size) { | ||
var e_5, _a; | ||
var e_2, _a; | ||
var rState = state; | ||
@@ -394,3 +331,3 @@ var index = size; | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
@@ -400,3 +337,3 @@ try { | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
@@ -471,3 +408,3 @@ return _this.stateToResult(rState, index); | ||
stateToResult: function (combinedState) { | ||
var e_6, _a; | ||
var e_3, _a; | ||
var state = combinedState.state; | ||
@@ -481,3 +418,3 @@ var index = 0; | ||
} | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
@@ -487,3 +424,3 @@ try { | ||
} | ||
finally { if (e_6) throw e_6.error; } | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
@@ -671,3 +608,3 @@ return _this.stateToResult(state, index); | ||
next: function (combinedState, elem) { | ||
var e_7, _a; | ||
var e_4, _a; | ||
if (combinedState.toRemove <= 0) { | ||
@@ -685,3 +622,3 @@ if ((amount === undefined || combinedState.amountLeft > 0) && | ||
} | ||
catch (e_7_1) { e_7 = { error: e_7_1 }; } | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
@@ -691,3 +628,3 @@ try { | ||
} | ||
finally { if (e_7) throw e_7.error; } | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
@@ -724,2 +661,10 @@ } | ||
}; | ||
/** | ||
* Returns a Collector where between each two elements, the given `elem` is added as extra input. | ||
* @param elem the element to insert between input elements | ||
*/ | ||
StateCollector.prototype.intersperseInput = function (elem) { | ||
var insert = [elem]; | ||
return this.patchWhereInput(function (_, i) { return i > 0; }, 0, function () { return insert; }); | ||
}; | ||
return StateCollector; | ||
@@ -726,0 +671,0 @@ }()); |
@@ -58,2 +58,5 @@ /** | ||
function fixed<R>(result: R): Collector<any, R>; | ||
type MapCollector<A, CS extends [any, any, ...any[]]> = Collector<A, any>[] & { | ||
[K in keyof CS]: Collector<A, CS[K]>; | ||
}; | ||
/** | ||
@@ -64,23 +67,16 @@ * Returns a Collector where the provided GenCollectors are run in parallel. | ||
* @typeparam A the input element type | ||
* @typeparam R the output type of the provided `col1` | ||
* @typeparam R2 the output type of the provided `col2` | ||
* @typeparam CR a tuple corresponding to the output types of the input collectors | ||
* @typeparam GR the result type of the `combineFun` function | ||
* @param combineFun a function that takes the tupled output of all provided collectors, and combines them into one result value | ||
* @param col1 a Collector taking the same type of elements | ||
* @param col2 a Collector taking the same type of elements | ||
* @param otherCollectors a number of Collectors taking the same type of elements | ||
* @param collectors a number of Collectors taking the same type of elements as input | ||
*/ | ||
function combineWith<A, R, R2, GR>(combineFun: (...results: [R, R2, ...any[]]) => GR, col1: Collector<A, R>, col2: Collector<A, R2>, ...otherCollectors: Collector<A, any>[]): Collector<A, GR>; | ||
function combineWith<A, CR extends [unknown, unknown, ...unknown[]], GR>(combineFun: (...results: CR) => GR, ...collectors: MapCollector<A, CR>): Collector<A, GR>; | ||
/** | ||
* Returns a Collector running the provided Collectors are run in parallel. | ||
* The results are collected into an array. | ||
* Note: due to type system limitations only the type of the first other collector is kept | ||
* @typeparam A the input element type | ||
* @typeparam R the output type of the provided `col1` | ||
* @typeparam R2 the output type of the provided `col2` | ||
* @param col1 a Collector taking the same type of elements | ||
* @param col2 a Collector taking the same type of elements | ||
* @param otherCollectors a number of Collectors taking the same type of elements | ||
* @typeparam CR a tuple corresponding to the output types of the input collectors | ||
* @param collectors a number of Collectors taking the same type of elements as input | ||
*/ | ||
function combine<A, R, R2, GR extends [R, R2, ...unknown[]]>(col1: Collector<A, R>, col2: Collector<A, R2>, ...otherCollectors: Collector<A, unknown>[]): Collector<A, GR>; | ||
function combine<A, CR extends [unknown, unknown, ...unknown[]]>(...collectors: MapCollector<A, CR>): Collector<A, CR>; | ||
/** | ||
@@ -251,2 +247,7 @@ * Returns a collector that feeds all input to the first `col1` collector, and for each input element takes the output value | ||
patchElemInput(elem: A, remove: number, insert?: Iterable<A>, amount?: number): Collector<A, R>; | ||
/** | ||
* Returns a Collector where between each two elements, the given `elem` is added as extra input. | ||
* @param elem the element to insert between input elements | ||
*/ | ||
intersperseInput(elem: A): Collector<A, R>; | ||
} |
{ | ||
"name": "iternal", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Provides a powerful API for native ES6 iterables and async iterables", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2268214
35875