@ts-common/iterator
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -133,2 +133,6 @@ /** | ||
readonly uniq: (key?: (v: T) => unknown) => IterableEx<T>; | ||
/** | ||
* Creates a new sequence of accamulated values. | ||
*/ | ||
readonly scan: <A>(func: (a: A, b: T, i: number) => A, init: A) => IterableEx<A>; | ||
}; | ||
@@ -155,2 +159,3 @@ export declare const iterable: <T>(createIterator: () => Iterator<T>) => IterableEx<T>; | ||
export declare const repeat: <T>(v: T, count?: number | undefined) => IterableEx<T>; | ||
export declare const scan: <T, A>(input: Iterable<T> | undefined, func: (a: A, b: T, i: number) => A, init: A) => IterableEx<A>; | ||
export declare const fold: <T, A>(input: Iterable<T> | undefined, func: (a: A, b: T, i: number) => A, init: A) => A; | ||
@@ -157,0 +162,0 @@ export declare const reduce: <T>(input: Iterable<T> | undefined, func: (a: T, b: T, i: number) => T) => T | undefined; |
@@ -31,2 +31,3 @@ "use strict"; | ||
zip: property(exports.zip), | ||
scan: property(exports.scan), | ||
}; | ||
@@ -110,2 +111,12 @@ }; | ||
exports.repeat = (v, count) => exports.generate(() => v, count); | ||
exports.scan = (input, func, init) => exports.iterable(function* () { | ||
let result = init; | ||
yield result; | ||
/* tslint:disable-next-line:no-loop-statement */ | ||
for (const [index, value] of exports.entries(input)) { | ||
/* tslint:disable-next-line:no-expression-statement */ | ||
result = func(result, value, index); | ||
yield result; | ||
} | ||
}); | ||
exports.fold = (input, func, init) => { | ||
@@ -112,0 +123,0 @@ let result = init; |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -136,2 +136,6 @@ /** | ||
readonly uniq: (key?: (v: T) => unknown) => IterableEx<T>, | ||
/** | ||
* Creates a new sequence of accamulated values. | ||
*/ | ||
readonly scan: <A>(func: (a: A, b: T, i: number) => A, init: A) => IterableEx<A>, | ||
} | ||
@@ -168,2 +172,3 @@ | ||
zip: property(zip), | ||
scan: property(scan), | ||
} | ||
@@ -301,2 +306,18 @@ } | ||
export const scan = <T, A>( | ||
input: Iterable<T> | undefined, | ||
func: (a: A, b: T, i: number) => A, | ||
init: A, | ||
): IterableEx<A> => | ||
iterable(function *() { | ||
let result: A = init | ||
yield result | ||
/* tslint:disable-next-line:no-loop-statement */ | ||
for (const [index, value] of entries(input)) { | ||
/* tslint:disable-next-line:no-expression-statement */ | ||
result = func(result, value, index) | ||
yield result | ||
} | ||
}) | ||
export const fold = <T, A>( | ||
@@ -303,0 +324,0 @@ input: Iterable<T> | undefined, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63055
824