@ts-common/iterator
Advanced tools
Comparing version 0.0.17 to 0.0.19
export declare function iterable<T>(createIterator: () => Iterator<T>): Iterable<T>; | ||
export interface StringMap<T> { | ||
readonly [key: string]: T; | ||
} | ||
export declare function map<T, I>(input: Iterable<I>, func: (v: I, i: number) => T): Iterable<T>; | ||
@@ -10,11 +7,4 @@ export declare function filterMap<T, I>(input: Iterable<I>, func: (v: I, i: number) => T | undefined): Iterable<T>; | ||
export declare function flatMap<T, I>(input: Iterable<I>, func: (v: I, i: number) => Iterable<T>): Iterable<T>; | ||
export declare function entries<T>(input: StringMap<T | undefined>): Iterable<[string, T]>; | ||
export declare function names<T>(input: StringMap<T>): Iterable<string>; | ||
export declare function values<T>(input: StringMap<T | undefined>): Iterable<T>; | ||
export declare function entry<T>(name: string, value: T): [string, T]; | ||
export declare function getName<T>(nv: [string, T]): string; | ||
export declare function getValue<T>(nv: [string, T]): T; | ||
export declare function generate<T>(func: (i: number) => T, count?: number): Iterable<T>; | ||
export declare function repeat<T>(v: T, count?: number): Iterable<T>; | ||
export declare function groupBy<T>(input: Iterable<[string, T]>, reduceFunc: (a: T, b: T) => T): StringMap<T>; | ||
export declare function reduce<T>(input: Iterable<T>, func: (a: T, b: T) => T, init: T): T; | ||
@@ -25,4 +15,3 @@ export declare function reduce<T>(input: Iterable<T>, func: (a: T, b: T) => T): T | undefined; | ||
export declare function max(input: Iterable<number>): number; | ||
export declare function zip<T>(...inputs: Array<Iterable<T>>): Iterable<T[]>; | ||
export declare function stringMap<T>(input: Iterable<[string, T]>): StringMap<T>; | ||
export declare function zip<T>(...inputs: Array<Iterable<T>>): Iterable<ReadonlyArray<T>>; | ||
export declare function arrayEqual<T>(a: T[] | undefined, b: T[] | undefined, e: (ai: T, bi: T) => boolean): boolean; |
60
index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function iterable(createIterator) { | ||
class Implementation { | ||
[Symbol.iterator]() { | ||
return createIterator(); | ||
} | ||
} | ||
return new Implementation(); | ||
return { | ||
[Symbol.iterator]() { return createIterator(); }, | ||
}; | ||
} | ||
@@ -61,34 +58,2 @@ exports.iterable = iterable; | ||
exports.flatMap = flatMap; | ||
function entries(input) { | ||
function* iterator() { | ||
for (const name in input) { | ||
const value = input[name]; | ||
if (value !== undefined) { | ||
yield entry(name, value); | ||
} | ||
} | ||
} | ||
return iterable(iterator); | ||
} | ||
exports.entries = entries; | ||
function names(input) { | ||
return map(entries(input), getName); | ||
} | ||
exports.names = names; | ||
function values(input) { | ||
return map(entries(input), getValue); | ||
} | ||
exports.values = values; | ||
function entry(name, value) { | ||
return [name, value]; | ||
} | ||
exports.entry = entry; | ||
function getName(nv) { | ||
return nv[0]; | ||
} | ||
exports.getName = getName; | ||
function getValue(nv) { | ||
return nv[1]; | ||
} | ||
exports.getValue = getValue; | ||
function generate(func, count) { | ||
@@ -108,13 +73,2 @@ const f = count === undefined ? () => true : i => i < count; | ||
exports.repeat = repeat; | ||
function groupBy(input, reduceFunc) { | ||
const result = {}; | ||
for (const nv of input) { | ||
const n = getName(nv); | ||
const v = getValue(nv); | ||
const prior = result[n]; | ||
result[n] = prior === undefined ? v : reduceFunc(prior, v); | ||
} | ||
return result; | ||
} | ||
exports.groupBy = groupBy; | ||
function reduce(input, func, init) { | ||
@@ -159,10 +113,2 @@ for (const v of input) { | ||
exports.zip = zip; | ||
function stringMap(input) { | ||
const result = {}; | ||
for (const nv of input) { | ||
result[getName(nv)] = getValue(nv); | ||
} | ||
return result; | ||
} | ||
exports.stringMap = stringMap; | ||
function arrayEqual(a, b, e) { | ||
@@ -169,0 +115,0 @@ if (a === b) { |
{ | ||
"name": "@ts-common/iterator", | ||
"version": "0.0.17", | ||
"version": "0.0.19", | ||
"description": "Iterator library for JavaScript and TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
17332
145