@ts-common/iterator
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -48,2 +48,3 @@ import { Tuple2 } from "@ts-common/tuple"; | ||
export declare const dropRight: <T>(i: ReadonlyArray<T> | undefined, n?: number) => Iterable<T>; | ||
export declare const uniq: <T>(i: Iterable<T>, key?: (v: T) => unknown) => Iterable<T>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -154,2 +154,15 @@ "use strict"; | ||
exports.dropRight = (i, n = 1) => i === undefined ? [] : exports.take(i, i.length - n); | ||
exports.uniq = (i, key = v => v) => exports.iterable(function* () { | ||
const set = new Set(); | ||
// tslint:disable-next-line:no-loop-statement | ||
for (const v of i) { | ||
const k = key(v); | ||
// tslint:disable-next-line:no-if-statement | ||
if (!set.has(k)) { | ||
// tslint:disable-next-line:no-expression-statement | ||
set.add(k); | ||
yield v; | ||
} | ||
} | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -57,8 +57,8 @@ "main": "dist/index.js", | ||
"tslint": "^5.12.1", | ||
"tslint-immutable": "^5.1.0", | ||
"typescript": "^3.2.2" | ||
"tslint-immutable": "^5.1.2", | ||
"typescript": "^3.3.1" | ||
}, | ||
"dependencies": { | ||
"@ts-common/tuple": "^0.0.5" | ||
"@ts-common/tuple": "^0.0.6" | ||
} | ||
} |
@@ -274,1 +274,16 @@ import { Tuple2, tuple2 } from "@ts-common/tuple" | ||
i === undefined ? [] : take(i, i.length - n) | ||
export const uniq = <T>(i: Iterable<T>, key: (v: T) => unknown = v => v): Iterable<T> => | ||
iterable(function *() { | ||
const set = new Set<unknown>() | ||
// tslint:disable-next-line:no-loop-statement | ||
for (const v of i) { | ||
const k = key(v) | ||
// tslint:disable-next-line:no-if-statement | ||
if (!set.has(k)) { | ||
// tslint:disable-next-line:no-expression-statement | ||
set.add(k) | ||
yield v | ||
} | ||
} | ||
}) |
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
42580
460
+ Added@ts-common/tuple@0.0.6(transitive)
- Removed@ts-common/tuple@0.0.5(transitive)
Updated@ts-common/tuple@^0.0.6