@ts-common/iterator
Advanced tools
Comparing version 0.0.24 to 0.0.26
@@ -15,6 +15,6 @@ import { Tuple2 } from "@ts-common/tuple"; | ||
export declare function repeat<T>(v: T, count?: number): Iterable<T>; | ||
export declare function lazyFold<T, A>(input: Iterable<T>, func: (a: A, b: T, i: number) => A, init: A): Iterable<A>; | ||
export declare function last<T>(input: Iterable<T>): T | undefined; | ||
export declare function fold<T, A>(input: Iterable<T>, func: (a: A, b: T, i: number) => A, init: A): A; | ||
export declare function reduce<T>(input: Iterable<T>, func: (a: T, b: T, i: number) => T): T | undefined; | ||
export declare function last<T>(input: Iterable<T>): T | undefined; | ||
export declare function some<T>(input: Iterable<T>, func: (v: T, i: number) => boolean): boolean; | ||
export declare function forEach<T>(input: Iterable<T>, func: (v: T, i: number) => void): void; | ||
@@ -21,0 +21,0 @@ export declare function sum(input: Iterable<number>): number; |
41
index.js
@@ -89,29 +89,11 @@ "use strict"; | ||
exports.repeat = repeat; | ||
function lazyFold(input, func, init) { | ||
function* iterator() { | ||
let result = init; | ||
/* 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; | ||
} | ||
} | ||
return iterable(iterator); | ||
} | ||
exports.lazyFold = lazyFold; | ||
function last(input) { | ||
let result; | ||
function fold(input, func, init) { | ||
let result = init; | ||
/* tslint:disable-next-line:no-loop-statement */ | ||
for (const v of input) { | ||
for (const [index, value] of entries(input)) { | ||
/* tslint:disable-next-line:no-expression-statement */ | ||
result = v; | ||
result = func(result, value, index); | ||
} | ||
return result; | ||
} | ||
exports.last = last; | ||
function fold(input, func, init) { | ||
const result = last(lazyFold(input, func, init)); | ||
return result !== undefined ? result : init; | ||
} | ||
exports.fold = fold; | ||
@@ -122,2 +104,17 @@ function reduce(input, func) { | ||
exports.reduce = reduce; | ||
function last(input) { | ||
return reduce(input, (_, v) => v); | ||
} | ||
exports.last = last; | ||
function some(input, func) { | ||
// tslint:disable-next-line:no-loop-statement | ||
for (const [index, value] of entries(input)) { | ||
// tslint:disable-next-line:no-if-statement | ||
if (func(value, index)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
exports.some = some; | ||
function forEach(input, func) { | ||
@@ -124,0 +121,0 @@ /* tslint:disable-next-line:no-expression-statement */ |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.0.24", | ||
"version": "0.0.26", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -40,5 +40,5 @@ "main": "index.js", | ||
"nyc": "^12.0.2", | ||
"tslint": "^5.10.0", | ||
"tslint": "^5.11.0", | ||
"tslint-immutable": "^4.6.0", | ||
"typescript": "^2.9.2" | ||
"typescript": "3.0.0-rc" | ||
}, | ||
@@ -45,0 +45,0 @@ "dependencies": { |
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
20636
206