@ts-common/iterator
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,2 +0,1 @@ | ||
import { Tuple2 } from "@ts-common/tuple"; | ||
export interface IteratorResult<T> { | ||
@@ -20,3 +19,3 @@ readonly done: boolean; | ||
readonly drop: (n?: number) => IterableEx<T>; | ||
readonly concat: (...input: Array<Iterable<T> | undefined>) => IterableEx<T>; | ||
readonly concat: (...input: readonly (Iterable<T> | undefined)[]) => IterableEx<T>; | ||
readonly takeWhile: (func: (v: T, i: number) => boolean) => IterableEx<T>; | ||
@@ -31,6 +30,6 @@ readonly take: (n?: number) => IterableEx<T>; | ||
readonly every: (func: (v: T, i: number) => boolean) => boolean; | ||
readonly zip: (...inputs: Array<Iterable<T> | undefined>) => IterableEx<ReadonlyArray<T>>; | ||
readonly zip: (...inputs: readonly (Iterable<T> | undefined)[]) => IterableEx<readonly T[]>; | ||
readonly isEqual: <B>(b: Iterable<B> | undefined, e?: (ai: T, bi: B) => boolean) => boolean; | ||
readonly toArray: () => ReadonlyArray<T>; | ||
readonly reverse: () => ReadonlyArray<T>; | ||
readonly toArray: () => readonly T[]; | ||
readonly reverse: () => readonly T[]; | ||
readonly isEmpty: () => boolean; | ||
@@ -40,18 +39,17 @@ readonly uniq: (key?: (v: T) => unknown) => IterableEx<T>; | ||
export declare const iterable: <T>(createIterator: () => Iterator<T>) => IterableEx<T>; | ||
export declare type Entry<T> = Tuple2<number, T>; | ||
export declare const entry: <T>(key: number, value: T) => Entry<T>; | ||
export declare type Entry<T> = readonly [number, T]; | ||
export declare const ENTRY_KEY = 0; | ||
export declare const ENTRY_VALUE = 1; | ||
export declare const chain: <T>(input: ReadonlyArray<T>) => IterableEx<T>; | ||
export declare const entries: <T>(input: Iterable<T> | undefined) => IterableEx<Tuple2<number, T>>; | ||
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 map: <T, I>(input: Iterable<I> | undefined, func: (v: I, i: number) => T) => IterableEx<T>; | ||
export declare const drop: <T>(input: Iterable<T> | undefined, n?: number) => IterableEx<T>; | ||
export declare const flat: <T>(input: Iterable<Iterable<T> | undefined> | undefined) => IterableEx<T>; | ||
export declare const concat: <T>(...input: (Iterable<T> | undefined)[]) => IterableEx<T>; | ||
export declare const concat: <T>(...input: readonly (Iterable<T> | undefined)[]) => IterableEx<T>; | ||
export declare const takeWhile: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => 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) => Tuple2<number, T> | undefined; | ||
export declare const findEntry: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => readonly [number, T] | undefined; | ||
export declare const find: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => T | undefined; | ||
export declare const flatMap: <T, I>(input: Iterable<I> | undefined, func: (v: I, i: number) => Iterable<T>) => IterableEx<T>; | ||
export declare const optionalToArray: <T>(v: T | undefined) => ReadonlyArray<T>; | ||
export declare const optionalToArray: <T>(v: T | undefined) => readonly T[]; | ||
export declare const filterMap: <T, I>(input: Iterable<I> | undefined, func: (v: I, i: number) => T | undefined) => IterableEx<T>; | ||
@@ -70,13 +68,13 @@ export declare const filter: <T>(input: Iterable<T> | undefined, func: (v: T, i: number) => boolean) => IterableEx<T>; | ||
export declare const max: (input: Iterable<number> | undefined) => number; | ||
export declare const zip: <T>(...inputs: (Iterable<T> | undefined)[]) => IterableEx<ReadonlyArray<T>>; | ||
export declare const zip: <T>(...inputs: readonly (Iterable<T> | undefined)[]) => IterableEx<readonly T[]>; | ||
export declare const isStrictEqual: (a: unknown, b: unknown) => boolean; | ||
export declare const isEqual: <A, B>(a: Iterable<A> | undefined, b: Iterable<B> | undefined, e?: (ai: A, bi: B) => boolean) => boolean; | ||
export declare const isArray: <T, U>(v: U | ReadonlyArray<T>) => v is ReadonlyArray<T>; | ||
export declare const toArray: <T>(i: Iterable<T> | undefined) => ReadonlyArray<T>; | ||
export declare const reverse: <T>(i: Iterable<T> | undefined) => ReadonlyArray<T>; | ||
export declare const isArray: <T, U>(v: U | readonly T[]) => v is readonly T[]; | ||
export declare const toArray: <T>(i: Iterable<T> | undefined) => readonly T[]; | ||
export declare const reverse: <T>(i: Iterable<T> | undefined) => readonly T[]; | ||
export declare const isEmpty: <T>(i: Iterable<T> | undefined) => boolean; | ||
export declare const join: (i: Iterable<string> | undefined, separator: string) => string; | ||
export declare const empty: <T>() => IterableEx<T>; | ||
export declare const dropRight: <T>(i: ReadonlyArray<T> | undefined, n?: number) => IterableEx<T>; | ||
export declare const dropRight: <T>(i: readonly T[] | undefined, n?: number) => IterableEx<T>; | ||
export declare const uniq: <T>(i: Iterable<T>, key?: (v: T) => unknown) => IterableEx<T>; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tuple_1 = require("@ts-common/tuple"); | ||
// tslint:disable-next-line:no-class | ||
@@ -10,3 +9,2 @@ class IterableImpl { | ||
} | ||
// tslint:disable-next-line:readonly-array | ||
concat(...input) { return exports.concat(this, ...input); } | ||
@@ -34,7 +32,5 @@ drop(n) { return exports.drop(this, n); } | ||
uniq(key) { return exports.uniq(this, key); } | ||
// tslint:disable-next-line:readonly-array | ||
zip(...inputs) { return exports.zip(this, ...inputs); } | ||
} | ||
exports.iterable = (createIterator) => new IterableImpl(createIterator); | ||
exports.entry = tuple_1.tuple2; | ||
exports.ENTRY_KEY = 0; | ||
@@ -51,3 +47,3 @@ exports.ENTRY_VALUE = 1; | ||
for (const value of input) { | ||
yield exports.entry(index, value); | ||
yield [index, value]; | ||
/* tslint:disable-next-line:no-expression-statement */ | ||
@@ -77,3 +73,2 @@ ++index; | ||
}); | ||
// tslint:disable-next-line:readonly-array | ||
exports.concat = (...input) => exports.flat(input); | ||
@@ -136,3 +131,2 @@ exports.takeWhile = (input, func) => exports.iterable(function* () { | ||
exports.max = (input) => exports.fold(input, (a, b) => Math.max(a, b), -Infinity); | ||
/* tslint:disable-next-line:readonly-array */ | ||
exports.zip = (...inputs) => exports.iterable(function* () { | ||
@@ -139,0 +133,0 @@ const iterators = inputs.map(i => i === undefined ? [][Symbol.iterator]() : i[Symbol.iterator]()); |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -56,8 +56,6 @@ "main": "dist/index.js", | ||
"tslint": "^5.14.0", | ||
"tslint-immutable": "^5.5.1", | ||
"typescript": "^3.3.4000" | ||
"tslint-immutable": "^5.5.2", | ||
"typescript": "^3.4.1" | ||
}, | ||
"dependencies": { | ||
"@ts-common/tuple": "^0.0.6" | ||
} | ||
"dependencies": {} | ||
} |
@@ -1,3 +0,1 @@ | ||
import { Tuple2, tuple2 } from "@ts-common/tuple" | ||
export interface IteratorResult<T> { | ||
@@ -24,4 +22,3 @@ readonly done: boolean; | ||
readonly drop: (n?: number) => IterableEx<T> | ||
// tslint:disable-next-line:readonly-array | ||
readonly concat: (...input: Array<Iterable<T>|undefined>) => IterableEx<T> | ||
readonly concat: (...input: readonly (Iterable<T>|undefined)[]) => IterableEx<T> | ||
readonly takeWhile: (func: (v: T, i: number) => boolean) => IterableEx<T> | ||
@@ -36,7 +33,6 @@ readonly take: (n?: number) => IterableEx<T> | ||
readonly every: (func: (v: T, i: number) => boolean) => boolean | ||
// tslint:disable-next-line:readonly-array | ||
readonly zip: (...inputs: Array<Iterable<T>|undefined>) => IterableEx<ReadonlyArray<T>> | ||
readonly zip: (...inputs: readonly (Iterable<T>|undefined)[]) => IterableEx<readonly T[]> | ||
readonly isEqual: <B>(b: Iterable<B>|undefined, e?: (ai: T, bi: B) => boolean) => boolean | ||
readonly toArray: () => ReadonlyArray<T> | ||
readonly reverse: () => ReadonlyArray<T> | ||
readonly toArray: () => readonly T[] | ||
readonly reverse: () => readonly T[] | ||
readonly isEmpty: () => boolean | ||
@@ -53,4 +49,3 @@ readonly uniq: (key?: (v: T) => unknown) => IterableEx<T> | ||
} | ||
// tslint:disable-next-line:readonly-array | ||
public concat(...input: Array<Iterable<T>|undefined>) { return concat(this, ...input) } | ||
public concat(...input: readonly (Iterable<T>|undefined)[]) { return concat(this, ...input) } | ||
public drop(n?: number) { return drop(this, n) } | ||
@@ -77,4 +72,3 @@ public entries() { return entries(this) } | ||
public uniq(key?: (v: T) => unknown) { return uniq(this, key) } | ||
// tslint:disable-next-line:readonly-array | ||
public zip(...inputs: Array<Iterable<T>|undefined>) { return zip(this, ...inputs) } | ||
public zip(...inputs: readonly (Iterable<T>|undefined)[]) { return zip(this, ...inputs) } | ||
} | ||
@@ -85,13 +79,11 @@ | ||
export type Entry<T> = Tuple2<number, T> | ||
export type Entry<T> = readonly [number, T] | ||
export const entry: <T>(key: number, value: T) => Entry<T> = tuple2 | ||
export const ENTRY_KEY = 0 | ||
export const ENTRY_VALUE = 1 | ||
export const chain = <T>(input: ReadonlyArray<T>): IterableEx<T> => iterable(() => input[Symbol.iterator]()) | ||
export const chain = <T>(input: readonly T[]): IterableEx<T> => iterable(() => input[Symbol.iterator]()) | ||
export const entries = <T>(input: Iterable<T>|undefined): IterableEx<Entry<T>> => | ||
iterable(function *(): Iterator<Entry<T>> { | ||
iterable(function *() { | ||
// tslint:disable-next-line:no-if-statement | ||
@@ -104,3 +96,3 @@ if (input === undefined) { | ||
for (const value of input) { | ||
yield entry(index, value) | ||
yield [index, value] as const | ||
/* tslint:disable-next-line:no-expression-statement */ | ||
@@ -140,4 +132,3 @@ ++index | ||
// tslint:disable-next-line:readonly-array | ||
export const concat = <T>(...input: Array<Iterable<T>|undefined>): IterableEx<T> => | ||
export const concat = <T>(...input: readonly (Iterable<T>|undefined)[]): IterableEx<T> => | ||
flat(input) | ||
@@ -191,3 +182,3 @@ | ||
export const optionalToArray = <T>(v: T|undefined): ReadonlyArray<T> => | ||
export const optionalToArray = <T>(v: T|undefined): readonly T[] => | ||
v === undefined ? [] : [v] | ||
@@ -271,5 +262,4 @@ | ||
/* tslint:disable-next-line:readonly-array */ | ||
export const zip = <T>(...inputs: Array<Iterable<T>|undefined>): IterableEx<ReadonlyArray<T>> => | ||
iterable(function *(): Iterator<ReadonlyArray<T>> { | ||
export const zip = <T>(...inputs: readonly (Iterable<T>|undefined)[]): IterableEx<readonly T[]> => | ||
iterable(function *(): Iterator<readonly T[]> { | ||
const iterators = inputs.map( | ||
@@ -328,9 +318,9 @@ i => i === undefined ? [][Symbol.iterator]() : i[Symbol.iterator](), | ||
export const isArray = <T, U>(v: ReadonlyArray<T>|U): v is ReadonlyArray<T> => | ||
export const isArray = <T, U>(v: readonly T[]|U): v is readonly T[] => | ||
v instanceof Array | ||
export const toArray = <T>(i: Iterable<T>|undefined): ReadonlyArray<T> => | ||
export const toArray = <T>(i: Iterable<T>|undefined): readonly T[] => | ||
i === undefined ? [] : Array.from(i) | ||
export const reverse = <T>(i: Iterable<T>|undefined): ReadonlyArray<T> => | ||
export const reverse = <T>(i: Iterable<T>|undefined): readonly T[] => | ||
fold(i, (a, b) => [b, ...a], new Array<T>()) | ||
@@ -349,3 +339,3 @@ | ||
export const dropRight = <T>(i: ReadonlyArray<T>|undefined, n: number = 1): IterableEx<T> => | ||
export const dropRight = <T>(i: readonly T[]|undefined, n: number = 1): IterableEx<T> => | ||
i === undefined ? empty() : take(i, i.length - n) | ||
@@ -352,0 +342,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
0
53835
571
- Removed@ts-common/tuple@^0.0.6
- Removed@ts-common/tuple@0.0.6(transitive)