Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ts-common/iterator

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-common/iterator - npm Package Compare versions

Comparing version 0.0.30 to 0.0.31

49

index.d.ts
import { Tuple2 } from "@ts-common/tuple";
export declare function iterable<T>(createIterator: () => Iterator<T>): Iterable<T>;
export declare const iterable: <T>(createIterator: () => Iterator<T>) => Iterable<T>;
export declare type Entry<T> = Tuple2<number, T>;
export declare const entry: <T>(key: number, value: T) => Entry<T>;
export declare function entries<T>(input: Iterable<T>): Iterable<Entry<T>>;
export declare function map<T, I>(input: Iterable<I>, func: (v: I, i: number) => T): Iterable<T>;
export declare function flatten<T>(input: Iterable<Iterable<T>>): Iterable<T>;
export declare function takeWhile<T>(input: Iterable<T>, func: (v: T, i: number) => boolean): Iterable<T>;
export declare function flatMap<T, I>(input: Iterable<I>, func: (v: I, i: number) => Iterable<T>): Iterable<T>;
export declare function optionalToArray<T>(v: T | undefined): ReadonlyArray<T>;
export declare function filterMap<T, I>(input: Iterable<I>, func: (v: I, i: number) => T | undefined): Iterable<T>;
export declare function filter<T>(input: Iterable<T>, func: (v: T, i: number) => boolean): Iterable<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 fold<T, A>(input: Iterable<T>, func: (a: A, b: T, i: number) => A, init: A): A;
export declare function reduce<T>(input: Iterable<T>, func: (a: T, b: T, i: number) => T): T | undefined;
export declare function last<T>(input: Iterable<T>): T | undefined;
export declare function find<T>(input: Iterable<T>, func: (v: T, i: number) => boolean): T | undefined;
export declare function some<T>(input: Iterable<T>, func: (v: T, i: number) => boolean): boolean;
export declare function forEach<T>(input: Iterable<T>, func: (v: T, i: number) => void): void;
export declare function sum(input: Iterable<number>): number;
export declare function min(input: Iterable<number>): number;
export declare function max(input: Iterable<number>): number;
export declare function zip<T>(...inputs: Array<Iterable<T>>): Iterable<ReadonlyArray<T>>;
export declare function arrayEqual<T>(a: ReadonlyArray<T> | undefined, b: ReadonlyArray<T> | undefined, e: (ai: T, bi: T) => boolean): boolean;
export declare function isArray<T, U>(v: ReadonlyArray<T> | U): v is ReadonlyArray<T>;
export declare const entries: <T>(input: Iterable<T>) => Iterable<Tuple2<number, T>>;
export declare const map: <T, I>(input: Iterable<I>, func: (v: I, i: number) => T) => Iterable<T>;
export declare const flatten: <T>(input: Iterable<Iterable<T>>) => Iterable<T>;
export declare const concat: <T>(...input: Iterable<T>[]) => Iterable<T>;
export declare const takeWhile: <T>(input: Iterable<T>, func: (v: T, i: number) => boolean) => Iterable<T>;
export declare const flatMap: <T, I>(input: Iterable<I>, func: (v: I, i: number) => Iterable<T>) => Iterable<T>;
export declare const optionalToArray: <T>(v: T | undefined) => ReadonlyArray<T>;
export declare const filterMap: <T, I>(input: Iterable<I>, func: (v: I, i: number) => T | undefined) => Iterable<T>;
export declare const filter: <T>(input: Iterable<T>, func: (v: T, i: number) => boolean) => Iterable<T>;
export declare const generate: <T>(func: (i: number) => T, count?: number | undefined) => Iterable<T>;
export declare const repeat: <T>(v: T, count?: number | undefined) => Iterable<T>;
export declare const fold: <T, A>(input: Iterable<T>, func: (a: A, b: T, i: number) => A, init: A) => A;
export declare const reduce: <T>(input: Iterable<T>, func: (a: T, b: T, i: number) => T) => T | undefined;
export declare const last: <T>(input: Iterable<T>) => T | undefined;
export declare const find: <T>(input: Iterable<T>, func: (v: T, i: number) => boolean) => T | undefined;
export declare const some: <T>(input: Iterable<T>, func: (v: T, i: number) => boolean) => boolean;
export declare const every: <T>(input: Iterable<T>, func: (v: T, i: number) => boolean) => boolean;
export declare const forEach: <T>(input: Iterable<T>, func: (v: T, i: number) => void) => void;
export declare const sum: (input: Iterable<number>) => number;
export declare const min: (input: Iterable<number>) => number;
export declare const max: (input: Iterable<number>) => number;
export declare const zip: <T>(...inputs: Iterable<T>[]) => Iterable<ReadonlyArray<T>>;
export declare const arrayEqual: <T>(a: ReadonlyArray<T> | undefined, b: ReadonlyArray<T> | undefined, e: (ai: T, bi: T) => boolean) => boolean;
export declare const isArray: <T, U>(v: U | ReadonlyArray<T>) => v is ReadonlyArray<T>;
export declare const toArray: <T>(i: Iterable<T>) => ReadonlyArray<T>;
export declare function concat<T>(...a: Array<Iterable<T>>): Iterable<T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tuple_1 = require("@ts-common/tuple");
function iterable(createIterator) {
return { [Symbol.iterator]: createIterator };
}
exports.iterable = iterable;
exports.iterable = (createIterator) => ({ [Symbol.iterator]: createIterator });
exports.entry = tuple_1.tuple2;
function entries(input) {
exports.entries = (input) => {
function* iterator() {

@@ -19,16 +16,14 @@ let index = 0;

}
return iterable(iterator);
}
exports.entries = entries;
function map(input, func) {
return exports.iterable(iterator);
};
exports.map = (input, func) => {
function* iterator() {
/* tslint:disable-next-line:no-loop-statement */
for (const [index, value] of entries(input)) {
for (const [index, value] of exports.entries(input)) {
yield func(value, index);
}
}
return iterable(iterator);
}
exports.map = map;
function flatten(input) {
return exports.iterable(iterator);
};
exports.flatten = (input) => {
function* iterator() {

@@ -40,9 +35,10 @@ /* tslint:disable-next-line:no-loop-statement */

}
return iterable(iterator);
}
exports.flatten = flatten;
function takeWhile(input, func) {
return exports.iterable(iterator);
};
// tslint:disable-next-line:readonly-array
exports.concat = (...input) => exports.flatten(input);
exports.takeWhile = (input, func) => {
function* iterator() {
/* tslint:disable-next-line:no-loop-statement */
for (const [index, value] of entries(input)) {
for (const [index, value] of exports.entries(input)) {
/* tslint:disable-next-line:no-if-statement */

@@ -55,22 +51,9 @@ if (!func(value, index)) {

}
return iterable(iterator);
}
exports.takeWhile = takeWhile;
function flatMap(input, func) {
return flatten(map(input, func));
}
exports.flatMap = flatMap;
function optionalToArray(v) {
return v === undefined ? [] : [v];
}
exports.optionalToArray = optionalToArray;
function filterMap(input, func) {
return flatMap(input, (v, i) => optionalToArray(func(v, i)));
}
exports.filterMap = filterMap;
function filter(input, func) {
return flatMap(input, (v, i) => func(v, i) ? [v] : []);
}
exports.filter = filter;
function infinite() {
return exports.iterable(iterator);
};
exports.flatMap = (input, func) => exports.flatten(exports.map(input, func));
exports.optionalToArray = (v) => v === undefined ? [] : [v];
exports.filterMap = (input, func) => exports.flatMap(input, (v, i) => exports.optionalToArray(func(v, i)));
exports.filter = (input, func) => exports.flatMap(input, (v, i) => func(v, i) ? [v] : []);
const infinite = () => {
function* iterator() {

@@ -82,16 +65,10 @@ /* tslint:disable-next-line:no-loop-statement */

}
return iterable(iterator);
}
function generate(func, count) {
return map(takeWhile(infinite(), (_, i) => i !== count), (_, i) => func(i));
}
exports.generate = generate;
function repeat(v, count) {
return generate(() => v, count);
}
exports.repeat = repeat;
function fold(input, func, init) {
return exports.iterable(iterator);
};
exports.generate = (func, count) => exports.map(exports.takeWhile(infinite(), (_, i) => i !== count), (_, i) => func(i));
exports.repeat = (v, count) => exports.generate(() => v, count);
exports.fold = (input, func, init) => {
let result = init;
/* tslint:disable-next-line:no-loop-statement */
for (const [index, value] of entries(input)) {
for (const [index, value] of exports.entries(input)) {
/* tslint:disable-next-line:no-expression-statement */

@@ -101,15 +78,8 @@ result = func(result, value, index);

return result;
}
exports.fold = fold;
function reduce(input, func) {
return fold(input, (a, b, i) => a !== undefined ? func(a, b, i) : b, undefined);
}
exports.reduce = reduce;
function last(input) {
return reduce(input, (_, v) => v);
}
exports.last = last;
function find(input, func) {
};
exports.reduce = (input, func) => exports.fold(input, (a, b, i) => a !== undefined ? func(a, b, i) : b, undefined);
exports.last = (input) => exports.reduce(input, (_, v) => v);
exports.find = (input, func) => {
// tslint:disable-next-line:no-loop-statement
for (const [index, value] of entries(input)) {
for (const [index, value] of exports.entries(input)) {
// tslint:disable-next-line:no-if-statement

@@ -121,27 +91,13 @@ if (func(value, index)) {

return undefined;
}
exports.find = find;
function some(input, func) {
return find(input, func) !== undefined;
}
exports.some = some;
function forEach(input, func) {
/* tslint:disable-next-line:no-expression-statement */
fold(input, (_, v, i) => { func(v, i); }, undefined);
}
exports.forEach = forEach;
function sum(input) {
return fold(input, (a, b) => a + b, 0);
}
exports.sum = sum;
function min(input) {
return fold(input, (a, b) => Math.min(a, b), Infinity);
}
exports.min = min;
function max(input) {
return fold(input, (a, b) => Math.max(a, b), -Infinity);
}
exports.max = max;
};
exports.some = (input, func) => exports.find(input, func) !== undefined;
exports.every = (input, func) => !exports.some(input, (v, i) => !func(v, i));
exports.forEach = (input, func) =>
/* tslint:disable-next-line:no-expression-statement */
exports.fold(input, (_, v, i) => { func(v, i); }, undefined);
exports.sum = (input) => exports.fold(input, (a, b) => a + b, 0);
exports.min = (input) => exports.fold(input, (a, b) => Math.min(a, b), Infinity);
exports.max = (input) => exports.fold(input, (a, b) => Math.max(a, b), -Infinity);
/* tslint:disable-next-line:readonly-array */
function zip(...inputs) {
exports.zip = (...inputs) => {
function* iterator() {

@@ -153,3 +109,3 @@ const iterators = inputs.map(i => i[Symbol.iterator]());

/* tslint:disable-next-line:no-loop-statement */
for (const [index, it] of entries(iterators)) {
for (const [index, it] of exports.entries(iterators)) {
const v = it.next();

@@ -166,6 +122,5 @@ /* tslint:disable-next-line:no-if-statement */

}
return iterable(iterator);
}
exports.zip = zip;
function arrayEqual(a, b, e) {
return exports.iterable(iterator);
};
exports.arrayEqual = (a, b, e) => {
/* tslint:disable-next-line:no-if-statement */

@@ -193,19 +148,4 @@ if (a === b) {

return true;
}
exports.arrayEqual = arrayEqual;
function isArray(v) {
return v instanceof Array;
}
exports.isArray = isArray;
};
exports.isArray = (v) => v instanceof Array;
exports.toArray = Array.from;
// tslint:disable-next-line:readonly-array
function concat(...a) {
function* iterator() {
// tslint:disable-next-line:no-loop-statement
for (const i of a) {
yield* i;
}
}
return iterable(iterator);
}
exports.concat = concat;
{
"name": "@ts-common/iterator",
"version": "0.0.30",
"version": "0.0.31",
"description": "Iterator library for JavaScript and TypeScript",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc