@ts-common/iterator
Advanced tools
Comparing version 0.3.6 to 1.0.0
/** | ||
* See this PR https://github.com/microsoft/TypeScript/pull/30790 | ||
*/ | ||
export declare type IteratorResult<T> = { | ||
/** | ||
* - Has the value `true` if the iterator is past the end of the iterated sequence. In this case value optionally | ||
* specifies the return value of the iterator. | ||
* - Has the value `false` if the iterator was able to produce the next value in the sequence. This is equivalent of | ||
* not specifying the done property altogether. | ||
*/ | ||
readonly done: boolean; | ||
/** | ||
* any JavaScript value returned by the iterator. Can be omitted when done is true. | ||
*/ | ||
readonly value: T; | ||
}; | ||
export declare type Iterator<T> = { | ||
/** | ||
* Returns `IterableResult<T>`. | ||
*/ | ||
readonly next: () => IteratorResult<T>; | ||
}; | ||
export declare type Iterable<T> = { | ||
/** | ||
* The function returns an iterator. | ||
*/ | ||
readonly [Symbol.iterator]: () => Iterator<T>; | ||
}; | ||
export declare type IterableEx<T> = Iterable<T> & { | ||
@@ -146,3 +121,3 @@ /** | ||
}; | ||
export declare const iterable: <T>(createIterator: () => Iterator<T>) => IterableEx<T>; | ||
export declare const iterable: <T>(createIterator: () => Iterator<T, any, undefined>) => IterableEx<T>; | ||
export declare type Entry<T> = readonly [number, T]; | ||
@@ -152,3 +127,3 @@ export declare const ENTRY_KEY = 0; | ||
export declare const chain: <T>(input: readonly T[]) => IterableEx<T>; | ||
export declare const entries: <T>(input: Iterable<T> | undefined) => IterableEx<readonly [number, T]>; | ||
export declare const entries: <T>(input: Iterable<T> | undefined) => IterableEx<Entry<T>>; | ||
export declare const map: <T, I>(input: Iterable<I> | undefined, func: (v: I, i: number) => T) => IterableEx<T>; | ||
@@ -160,3 +135,3 @@ export declare const drop: <T>(input: Iterable<T> | undefined, n?: number) => IterableEx<T>; | ||
export declare const take: <T>(input: Iterable<T> | undefined, n?: number) => IterableEx<T>; | ||
export declare const findEntry: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => readonly [number, T] | undefined; | ||
export declare const findEntry: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => Entry<T> | undefined; | ||
export declare const find: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => T | undefined; | ||
@@ -163,0 +138,0 @@ export declare const flatMap: <T, I>(input: Iterable<I> | undefined, func: (v: I, i: number) => Iterable<T>) => IterableEx<T>; |
"use strict"; | ||
/** | ||
* See this PR https://github.com/microsoft/TypeScript/pull/30790 | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -157,4 +160,7 @@ exports.iterable = (createIterator) => { | ||
exports.forEach = (input, func) => { | ||
// tslint:disable-next-line:no-expression-statement | ||
exports.fold(input, (_, v, i) => { func(v, i); }, undefined); | ||
// tslint:disable-next-line: no-loop-statement | ||
for (const [index, value] of exports.entries(input)) { | ||
// tslint:disable-next-line: no-expression-statement | ||
func(value, index); | ||
} | ||
}; | ||
@@ -173,3 +179,3 @@ exports.sum = (input) => exports.fold(input, (a, b) => a + b, 0); | ||
// tslint:disable-next-line:no-if-statement | ||
if (v.done) { | ||
if (v.done === true) { | ||
return; | ||
@@ -201,3 +207,3 @@ } | ||
// tslint:disable-next-line:no-if-statement | ||
if (av.done || bv.done) { | ||
if (av.done === true || bv.done === true) { | ||
return av.done === bv.done; | ||
@@ -204,0 +210,0 @@ } |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.3.6", | ||
"version": "1.0.0", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -8,2 +8,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"tsc": "tsc", | ||
@@ -66,10 +67,10 @@ "tslint": "tslint --project tsconfig.json", | ||
"devDependencies": { | ||
"@types/jest": "^24.0.15", | ||
"jest": "^24.8.0", | ||
"jest-junit": "^6.4.0", | ||
"tslint": "^5.18.0", | ||
"tslint-immutable": "^6.0.0", | ||
"typescript": "^3.5.2" | ||
"@types/jest": "^24.9.0", | ||
"jest": "^24.9.0", | ||
"jest-junit": "^10.0.0", | ||
"tslint": "^5.20.1", | ||
"tslint-immutable": "^6.0.1", | ||
"typescript": "^3.7.5" | ||
}, | ||
"dependencies": {} | ||
} |
/** | ||
* See this PR https://github.com/microsoft/TypeScript/pull/30790 | ||
*/ | ||
export type IteratorResult<T> = { | ||
/** | ||
* - Has the value `true` if the iterator is past the end of the iterated sequence. In this case value optionally | ||
* specifies the return value of the iterator. | ||
* - Has the value `false` if the iterator was able to produce the next value in the sequence. This is equivalent of | ||
* not specifying the done property altogether. | ||
*/ | ||
readonly done: boolean; | ||
/** | ||
* any JavaScript value returned by the iterator. Can be omitted when done is true. | ||
*/ | ||
readonly value: T; | ||
} | ||
export type Iterator<T> = { | ||
/** | ||
* Returns `IterableResult<T>`. | ||
*/ | ||
readonly next: () => IteratorResult<T>; | ||
} | ||
export type Iterable<T> = { | ||
/** | ||
* The function returns an iterator. | ||
*/ | ||
readonly [Symbol.iterator]: () => Iterator<T>; | ||
} | ||
export type IterableEx<T> = Iterable<T> & { | ||
@@ -398,4 +371,7 @@ /** | ||
export const forEach = <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => void): void => { | ||
// tslint:disable-next-line:no-expression-statement | ||
fold<T, void>(input, (_, v, i) => { func(v, i) }, undefined) | ||
// tslint:disable-next-line: no-loop-statement | ||
for (const [index, value] of entries(input)) { | ||
// tslint:disable-next-line: no-expression-statement | ||
func(value, index) | ||
} | ||
} | ||
@@ -424,3 +400,3 @@ | ||
// tslint:disable-next-line:no-if-statement | ||
if (v.done) { | ||
if (v.done === true) { | ||
return | ||
@@ -458,3 +434,3 @@ } | ||
// tslint:disable-next-line:no-if-statement | ||
if (av.done || bv.done) { | ||
if (av.done === true || bv.done === true) { | ||
return av.done === bv.done | ||
@@ -461,0 +437,0 @@ } |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
65194
850