@ts-common/iterator
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,12 +0,12 @@ | ||
export interface IteratorResult<T> { | ||
export declare type IteratorResult<T> = { | ||
readonly done: boolean; | ||
readonly value: T; | ||
} | ||
export interface Iterator<T> { | ||
}; | ||
export declare type Iterator<T> = { | ||
readonly next: () => IteratorResult<T>; | ||
} | ||
export interface Iterable<T> { | ||
}; | ||
export declare type Iterable<T> = { | ||
readonly [Symbol.iterator]: () => Iterator<T>; | ||
} | ||
export interface IterableEx<T> extends Iterable<T> { | ||
}; | ||
export declare type IterableEx<T> = Iterable<T> & { | ||
readonly entries: () => IterableEx<Entry<T>>; | ||
@@ -35,3 +35,3 @@ readonly map: <R>(func: (v: T, i: number) => R) => IterableEx<R>; | ||
readonly uniq: (key?: (v: T) => unknown) => IterableEx<T>; | ||
} | ||
}; | ||
export declare const iterable: <T>(createIterator: () => Iterator<T>) => IterableEx<T>; | ||
@@ -38,0 +38,0 @@ export declare type Entry<T> = readonly [number, T]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable-next-line:no-class | ||
class IterableImpl { | ||
constructor(createIterator) { | ||
// tslint:disable-next-line:no-expression-statement | ||
this[Symbol.iterator] = createIterator; | ||
} | ||
concat(...input) { return exports.concat(this, ...input); } | ||
drop(n) { return exports.drop(this, n); } | ||
entries() { return exports.entries(this); } | ||
every(func) { return exports.every(this, func); } | ||
filter(func) { return exports.filter(this, func); } | ||
filterMap(func) { return exports.filterMap(this, func); } | ||
find(func) { return exports.find(this, func); } | ||
findEntry(func) { return exports.findEntry(this, func); } | ||
flatMap(func) { return exports.flatMap(this, func); } | ||
fold(func, init) { return exports.fold(this, func, init); } | ||
forEach(func) { return exports.forEach(this, func); } | ||
isEmpty() { return exports.isEmpty(this); } | ||
isEqual(b, e) { return exports.isEqual(this, b, e); } | ||
last() { return exports.last(this); } | ||
map(func) { return exports.map(this, func); } | ||
reduce(func) { return exports.reduce(this, func); } | ||
reverse() { return exports.reverse(this); } | ||
some(func) { return exports.some(this, func); } | ||
take(n) { return exports.take(this, n); } | ||
takeWhile(func) { return exports.takeWhile(this, func); } | ||
toArray() { return exports.toArray(this); } | ||
uniq(key) { return exports.uniq(this, key); } | ||
zip(...inputs) { return exports.zip(this, ...inputs); } | ||
} | ||
exports.iterable = (createIterator) => new IterableImpl(createIterator); | ||
exports.iterable = (createIterator) => { | ||
const property = (f) => (...p) => f(result, ...p); | ||
const result = { | ||
[Symbol.iterator]: createIterator, | ||
concat: property(exports.concat), | ||
drop: property(exports.drop), | ||
entries: property(exports.entries), | ||
every: property(exports.every), | ||
filter: property(exports.filter), | ||
filterMap: property(exports.filterMap), | ||
find: property(exports.find), | ||
findEntry: property(exports.findEntry), | ||
flatMap: property(exports.flatMap), | ||
fold: property(exports.fold), | ||
forEach: property(exports.forEach), | ||
isEmpty: property(exports.isEmpty), | ||
isEqual: property(exports.isEqual), | ||
last: property(exports.last), | ||
map: property(exports.map), | ||
reduce: property(exports.reduce), | ||
reverse: property(exports.reverse), | ||
some: property(exports.some), | ||
take: property(exports.take), | ||
takeWhile: property(exports.takeWhile), | ||
toArray: property(exports.toArray), | ||
uniq: property(exports.uniq), | ||
zip: property(exports.zip), | ||
}; | ||
return result; | ||
}; | ||
exports.ENTRY_KEY = 0; | ||
@@ -35,0 +34,0 @@ exports.ENTRY_VALUE = 1; |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"nyc": { | ||
"reporter": [ | ||
"text", | ||
"cobertura", | ||
"html" | ||
], | ||
"include": [ | ||
"dist/*.js" | ||
], | ||
"check-coverage": true, | ||
"lines": 100, | ||
"statements": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"scripts": { | ||
@@ -26,4 +11,35 @@ "tsc": "tsc", | ||
"prepack": "npm install && tsc", | ||
"test": "tsc && npm run tslint && nyc mocha ./dist/test/*.js --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporters.json" | ||
"test": "tsc && npm run tslint && jest" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"testMatch": [ | ||
"**/dist/test/*test.js" | ||
], | ||
"reporters": [ | ||
"jest-junit", | ||
"default" | ||
], | ||
"collectCoverage": true, | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100, | ||
"statements": 100 | ||
} | ||
}, | ||
"coveragePathIgnorePatterns": [ | ||
"/dist/test/" | ||
], | ||
"coverageReporters": [ | ||
"cobertura", | ||
"text", | ||
"html" | ||
] | ||
}, | ||
"jest-junit": { | ||
"outputDirectory": ".", | ||
"outputName": "test-results.xml" | ||
}, | ||
"repository": { | ||
@@ -50,13 +66,11 @@ "type": "git", | ||
"devDependencies": { | ||
"@types/mocha": "^5.2.6", | ||
"@types/jest": "^24.0.12", | ||
"@types/node": "^11.9.3", | ||
"mocha": "^6.0.2", | ||
"mocha-junit-reporter": "^1.18.0", | ||
"mocha-multi-reporters": "^1.1.7", | ||
"nyc": "^13.3.0", | ||
"tslint": "^5.14.0", | ||
"jest": "^24.8.0", | ||
"jest-junit": "^6.4.0", | ||
"tslint": "^5.16.0", | ||
"tslint-immutable": "^5.5.2", | ||
"typescript": "^3.4.1" | ||
"typescript": "^3.4.5" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -1,2 +0,2 @@ | ||
export interface IteratorResult<T> { | ||
export type IteratorResult<T> = { | ||
readonly done: boolean; | ||
@@ -6,11 +6,11 @@ readonly value: T; | ||
export interface Iterator<T> { | ||
export type Iterator<T> = { | ||
readonly next: () => IteratorResult<T>; | ||
} | ||
export interface Iterable<T> { | ||
export type Iterable<T> = { | ||
readonly [Symbol.iterator]: () => Iterator<T>; | ||
} | ||
export interface IterableEx<T> extends Iterable<T> { | ||
export type IterableEx<T> = Iterable<T> & { | ||
readonly entries: () => IterableEx<Entry<T>> | ||
@@ -38,40 +38,37 @@ readonly map: <R>(func: (v: T, i: number) => R) => IterableEx<R> | ||
readonly isEmpty: () => boolean | ||
readonly uniq: (key?: (v: T) => unknown) => IterableEx<T> | ||
readonly uniq: (key?: (v: T) => unknown) => IterableEx<T>, | ||
} | ||
// tslint:disable-next-line:no-class | ||
class IterableImpl<T> implements IterableEx<T> { | ||
public readonly [Symbol.iterator]: () => Iterator<T> | ||
constructor(createIterator: () => Iterator<T>) { | ||
// tslint:disable-next-line:no-expression-statement | ||
this[Symbol.iterator] = createIterator | ||
export const iterable = <T>(createIterator: () => Iterator<T>): IterableEx<T> => { | ||
const property = <P extends readonly unknown[], R>(f: (self: Iterable<T>, ...p: P) => R) => | ||
(...p: P) => f(result, ...p) | ||
const result: IterableEx<T> = { | ||
[Symbol.iterator]: createIterator, | ||
concat: property(concat), | ||
drop: property(drop), | ||
entries: property(entries), | ||
every: property(every), | ||
filter: property(filter), | ||
filterMap: property(filterMap), | ||
find: property(find), | ||
findEntry: property(findEntry), | ||
flatMap: property(flatMap), | ||
fold: property(fold), | ||
forEach: property(forEach), | ||
isEmpty: property(isEmpty), | ||
isEqual: property(isEqual), | ||
last: property(last), | ||
map: property(map), | ||
reduce: property(reduce), | ||
reverse: property(reverse), | ||
some: property(some), | ||
take: property(take), | ||
takeWhile: property(takeWhile), | ||
toArray: property(toArray), | ||
uniq: property(uniq), | ||
zip: property(zip), | ||
} | ||
public concat(...input: readonly (Iterable<T>|undefined)[]) { return concat(this, ...input) } | ||
public drop(n?: number) { return drop(this, n) } | ||
public entries() { return entries(this) } | ||
public every(func: (v: T, i: number) => boolean) { return every(this, func) } | ||
public filter(func: (v: T, i: number) => boolean) { return filter(this, func) } | ||
public filterMap<R>(func: (v: T, i: number) => R|undefined) { return filterMap(this, func) } | ||
public find(func: (v: T, i: number) => boolean) { return find(this, func) } | ||
public findEntry(func: (v: T, i: number) => boolean) { return findEntry(this, func) } | ||
public flatMap<R>(func: (v: T, i: number) => Iterable<R>) { return flatMap(this, func) } | ||
public fold<A>(func: (a: A, b: T, i: number) => A, init: A) { return fold(this, func, init) } | ||
public forEach(func: (v: T, i: number) => void) { return forEach(this, func) } | ||
public isEmpty() { return isEmpty(this) } | ||
public isEqual<B>(b: Iterable<B>|undefined, e?: (ai: T, bi: B) => boolean) { return isEqual(this, b, e) } | ||
public last() { return last(this) } | ||
public map<R>(func: (v: T, i: number) => R) { return map(this, func) } | ||
public reduce(func: (a: T, b: T, i: number) => T) { return reduce(this, func) } | ||
public reverse() { return reverse(this) } | ||
public some(func?: (v: T, i: number) => boolean) { return some(this, func) } | ||
public take(n?: number) { return take(this, n) } | ||
public takeWhile(func: (v: T, i: number) => boolean) { return takeWhile(this, func) } | ||
public toArray() { return toArray(this) } | ||
public uniq(key?: (v: T) => unknown) { return uniq(this, key) } | ||
public zip(...inputs: readonly (Iterable<T>|undefined)[]) { return zip(this, ...inputs) } | ||
return result | ||
} | ||
export const iterable = <T>(createIterator: () => Iterator<T>): IterableEx<T> => | ||
new IterableImpl(createIterator) | ||
export type Entry<T> = readonly [number, T] | ||
@@ -149,3 +146,3 @@ | ||
export const findEntry = <T>( | ||
export const findEntry = <T>( | ||
input: Iterable<T>|undefined, | ||
@@ -152,0 +149,0 @@ func: (v: T, i: number) => boolean, |
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
7
51793
568