Comparing version 1.1.0 to 1.1.1
@@ -25,2 +25,7 @@ "use strict"; | ||
(function (OptLazy) { | ||
/** | ||
* Returns an always lazy value of type `Lazy<T>` from an optionally lazy value of type `OptLazy<T>` | ||
* @typeparam T the value type | ||
* @param optLazy the optionally lazy input | ||
*/ | ||
function toLazy(optLazy) { | ||
@@ -32,2 +37,7 @@ if (typeof optLazy === 'function') | ||
OptLazy.toLazy = toLazy; | ||
/** | ||
* Returns the value of an optionally lazy value of type `OptLazy<T>` | ||
* @typeparam T the value type | ||
* @param optLazy the optionally lazy input | ||
*/ | ||
function toValue(optLazy) { | ||
@@ -34,0 +44,0 @@ return toLazy(optLazy)(); |
@@ -260,11 +260,3 @@ "use strict"; | ||
function StateCollector(definition) { | ||
var _this = this; | ||
this.definition = definition; | ||
var nextState = definition.nextState; | ||
this.definition.nextState = function (state, elem, index) { | ||
if (_this.monitorEffect !== undefined) { | ||
_this.monitorEffect([elem, state], index); | ||
} | ||
return nextState(state, elem, index); | ||
}; | ||
} | ||
@@ -321,18 +313,12 @@ /** | ||
* @param tag a tag to use with logging | ||
* @param monitorEffect the effect to perform for each input element | ||
* @param effect the effect to perform for each input element | ||
*/ | ||
StateCollector.prototype.monitorInput = function (tag, monitorEffect) { | ||
StateCollector.prototype.monitorInput = function (tag, effect) { | ||
var _this = this; | ||
if (tag === void 0) { tag = ''; } | ||
if (monitorEffect === void 0) { monitorEffect = defaultMonitorEffect; } | ||
if (this.monitorEffect === undefined) { | ||
this.monitorEffect = function (input, index) { return monitorEffect(input, index, tag); }; | ||
} | ||
else { | ||
var currentEffect_1 = this.monitorEffect; | ||
this.monitorEffect = function (input, index) { | ||
currentEffect_1(input, index); | ||
monitorEffect(input, index); | ||
}; | ||
} | ||
return this; | ||
if (effect === void 0) { effect = defaultMonitorEffect; } | ||
return new StateCollector(__assign({}, this.definition, { nextState: function (state, elem, index) { | ||
effect([elem, state], index, tag); | ||
return _this.definition.nextState(state, elem, index); | ||
} })); | ||
}; | ||
@@ -339,0 +325,0 @@ /** |
@@ -33,3 +33,13 @@ /** | ||
export declare namespace OptLazy { | ||
/** | ||
* Returns an always lazy value of type `Lazy<T>` from an optionally lazy value of type `OptLazy<T>` | ||
* @typeparam T the value type | ||
* @param optLazy the optionally lazy input | ||
*/ | ||
function toLazy<T>(optLazy: OptLazy<T>): Lazy<T>; | ||
/** | ||
* Returns the value of an optionally lazy value of type `OptLazy<T>` | ||
* @typeparam T the value type | ||
* @param optLazy the optionally lazy input | ||
*/ | ||
function toValue<T>(optLazy: OptLazy<T>): T; | ||
@@ -61,4 +71,13 @@ } | ||
export declare type ReduceFun<E, S> = (state: S, elem: E, index: number) => S; | ||
/** | ||
* An Iterable or AsyncIterable of element type E | ||
*/ | ||
export declare type AnyIterable<E> = Iterable<E> | AsyncIterable<E>; | ||
/** | ||
* An Iterator or AsyncIterator of element type E | ||
*/ | ||
export declare type AnyIterator<E> = Iterator<E> | AsyncIterator<E>; | ||
/** | ||
* Any type that is both iterable and indexable by number, and has a defined length | ||
*/ | ||
export declare type Indexed<E> = Iterable<E> & { | ||
@@ -73,2 +92,7 @@ [key: number]: E; | ||
export declare type MonitorEffect<E> = (value: E, index: number, tag?: string) => void; | ||
/** | ||
* A Map with keys K and each key having multiple values of type V. | ||
* @typeparam K the key type | ||
* @typeparam V the value type | ||
*/ | ||
export declare type Dict<K, V> = Map<K, V[]>; | ||
@@ -75,0 +99,0 @@ export declare namespace Dict { |
@@ -127,3 +127,2 @@ /** | ||
}): StateCollector<A, S, R>; | ||
private monitorEffect?; | ||
/** | ||
@@ -144,5 +143,5 @@ * Constructs a new Collector instance | ||
* @param tag a tag to use with logging | ||
* @param monitorEffect the effect to perform for each input element | ||
* @param effect the effect to perform for each input element | ||
*/ | ||
monitorInput(tag?: string, monitorEffect?: MonitorEffect<[A, S]>): Collector<A, R>; | ||
monitorInput(tag?: string, effect?: MonitorEffect<[A, S]>): Collector<A, R>; | ||
/** | ||
@@ -149,0 +148,0 @@ * Returns a Collector where the output value(s) are mapped using the given `mapFun` |
@@ -37,3 +37,2 @@ /** | ||
applyCustomOperation<R>(createIterator: (iterable: Iterable<T>) => Iterator<R>): Iter<R>; | ||
private monitorEffect?; | ||
/** | ||
@@ -78,3 +77,3 @@ * Iterable interface: When called, returns an Iterator of type T | ||
* iter.of(1, 3, 5).map((value, index) => value + index) | ||
* result: (1, 5, 8) | ||
* result: (1, 4, 7) | ||
* ``` | ||
@@ -437,6 +436,5 @@ */ | ||
/** | ||
* Allows side-effects at any point in the chain, but does not modify the Iter, it just returns the same Iter instance. | ||
* Allows side-effects at any point in the chain, but does not modify the Iter. | ||
* @param tag a tag that can be used when performing the side-effect | ||
* @param effect the side-effect to perform for each yielded element | ||
* @returns this exact instance | ||
* @example | ||
@@ -820,3 +818,2 @@ * ```typescript | ||
applyCustomOperation<R>(createIterator: (iterable: AsyncIterable<T>) => AsyncIterator<R>): AsyncIter<R>; | ||
private monitorEffect?; | ||
/** | ||
@@ -861,3 +858,3 @@ * AsyncIterable interface: When called, returns an AsyncIterator of type T | ||
* asyncIter([1, 3, 5]).map((value, index) => value + index) | ||
* result: (1, 5, 8) | ||
* result: (1, 4, 7) | ||
* ``` | ||
@@ -1220,6 +1217,5 @@ */ | ||
/** | ||
* Allows side-effects at any point in the chain, but does not modify the Iter, it just returns the same AsyncIter instance. | ||
* Allows side-effects at any point in the chain, but does not modify the Iter. | ||
* @param tag a tag that can be used when performing the side-effect | ||
* @param effect the side-effect to perform for each yielded element | ||
* @returns this exact instance | ||
* ```typescript | ||
@@ -1226,0 +1222,0 @@ * iter.nats.toAsync().monitor("nats").take(3) |
{ | ||
"name": "iternal", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Provides a powerful API for native ES6 iterables and async iterables", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -186,3 +186,3 @@ # iternal | ||
```typescript | ||
const wordLengthSum = sumCollector.mapInput(word => word.length) | ||
const wordLengthSum = sumCollector.mapInput<string>(word => word.length) | ||
@@ -195,3 +195,3 @@ const totalLength = iter(arrayOfStrings, someOtherArrayOfStrings).collect(wordLengthSum) | ||
```typescript | ||
const wordLengthAverage = Collectors.average.mapInput(word => word.length) | ||
const wordLengthAverage = Collectors.average.mapInput<string>(word => word.length) | ||
@@ -222,3 +222,3 @@ const [totalLength, averageLength] = iter(arrayOfStrings).collect( | ||
It is interesting to note here that, as the list indicates, most of these operations should be read in backward order, since we are transforming are transforming a given input stream towards our desired input stream. | ||
It is interesting to note here that, as the list indicates, most of these operations should be read in backward order, since we are transforming a given input stream towards our desired input stream. | ||
@@ -258,3 +258,3 @@ Hopefully you see that you now probably never have to write a `for` loop over some Iterable again. | ||
```typescript | ||
const sumIsPrime = Collector.createMono({ | ||
const sumIsPrime: Collector<number, boolean> = Collector.createState({ | ||
init: 0, | ||
@@ -291,3 +291,7 @@ next: (state, elem) => state + elem, | ||
```typescript | ||
const efficientProduct = Collector.createMono({ init: 0, next: (state, value) => state * value, state => state === 0 }) | ||
const efficientProduct = Collector.createMono({ | ||
init: 0, | ||
next: (state, value) => state * value, | ||
escape: state => state === 0 | ||
}) | ||
``` | ||
@@ -354,4 +358,4 @@ | ||
next: (state, key) => { | ||
state[key] = 'init' | ||
return state | ||
state[key] = 'init' | ||
return state | ||
} | ||
@@ -358,0 +362,0 @@ }) |
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
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
36039
379
2280205