gensequence
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -20,3 +20,3 @@ import { Sequence, GenIterable } from './types'; | ||
export declare const toIterator: typeof toIterableIterator; | ||
export declare type KeyValuePair<T> = [keyof T, T[keyof T]]; | ||
export type KeyValuePair<T> = [keyof T, T[keyof T]]; | ||
export declare function objectIterator<T extends {}>(t: T): IterableIterator<KeyValuePair<T>>; | ||
@@ -23,0 +23,0 @@ export declare function objectToSequence<T extends {}>(t: T): Sequence<KeyValuePair<T>>; |
@@ -13,5 +13,17 @@ "use strict"; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -22,4 +34,4 @@ exports.operators = void 0; | ||
__exportStar(require("./builder"), exports); | ||
const _operators = require("./operators"); | ||
const _operators = __importStar(require("./operators")); | ||
exports.operators = _operators; | ||
//# sourceMappingURL=index.js.map |
@@ -39,3 +39,3 @@ import { ChainFunction, IterableLike, Maybe, ReduceAsyncFunction, ReduceAsyncFunctionForAsyncIterator, ReduceFunction, ThenArg } from '../types'; | ||
export declare function reduceAsyncForAsyncIterator<T>(fnReduceAsync: (previousValue: ThenArg<T>, currentValue: ThenArg<T>, currentIndex: number) => ThenArg<T> | Promise<ThenArg<T>>, initialValue?: ThenArg<T>): ReduceAsyncFunctionForAsyncIterator<T, Promise<ThenArg<T>>>; | ||
export declare type PipeFunction<T, U = T> = ChainFunction<T, U>; | ||
export type PipeFunction<T, U = T> = ChainFunction<T, U>; | ||
export declare function pipe<T>(): PipeFunction<T>; | ||
@@ -42,0 +42,0 @@ export declare function pipe<T, T1>(fn0: PipeFunction<T, T1>): PipeFunction<T, T1>; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pipe = exports.reduceAsyncForAsyncIterator = exports.reduceAsync = exports.reduce = exports.min = exports.max = exports.forEach = exports.first = exports.count = exports.any = exports.all = exports.scan = exports.map = exports.combine = exports.concatMap = exports.concat = exports.take = exports.skip = exports.filter = void 0; | ||
const op = require("./operatorsBase"); | ||
const op = __importStar(require("./operatorsBase")); | ||
/** | ||
@@ -6,0 +29,0 @@ * Operators used by Sequence |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __asyncValues = (this && this.__asyncValues) || function (o) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var m = o[Symbol.asyncIterator], i; | ||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); | ||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } | ||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } | ||
}; | ||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } | ||
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { | ||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); | ||
var g = generator.apply(thisArg, _arguments || []), i, q = []; | ||
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; | ||
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } | ||
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } | ||
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } | ||
function fulfill(value) { resume("next", value); } | ||
function reject(value) { resume("throw", value); } | ||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } | ||
}; | ||
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) { | ||
var i, p; | ||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; | ||
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; } | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -199,51 +166,36 @@ exports.scanMap = exports.isAsyncIterableIterator = exports.isAsyncIterable = exports.makeAsyncIterable = exports.isIterableIterator = exports.isIterable = exports.makeIterable = exports.reduceAsyncForAsyncIterator = exports.reduceAsync = exports.reduce = exports.min = exports.max = exports.forEach = exports.first = exports.count = exports.any = exports.all = exports.scan = exports.map = exports.combine = exports.concatMap = exports.concat = exports.take = exports.skip = exports.filter = void 0; | ||
exports.reduce = reduce; | ||
function reduceAsync(i, fnReduce, initialValue) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// We need to create a new iterable to prevent for...of from restarting an array. | ||
const iter = makeIterable(i[Symbol.iterator]()); | ||
let index = 0; | ||
if (initialValue === undefined) { | ||
index = 1; | ||
const r = iter.next(); | ||
initialValue = r.value; | ||
} | ||
let previousValue = yield initialValue; | ||
for (const p of iter) { | ||
const t = yield p; | ||
const nextValue = yield fnReduce(previousValue, t, index); | ||
previousValue = nextValue; | ||
index += 1; | ||
} | ||
return previousValue; | ||
}); | ||
async function reduceAsync(i, fnReduce, initialValue) { | ||
// We need to create a new iterable to prevent for...of from restarting an array. | ||
const iter = makeIterable(i[Symbol.iterator]()); | ||
let index = 0; | ||
if (initialValue === undefined) { | ||
index = 1; | ||
const r = iter.next(); | ||
initialValue = r.value; | ||
} | ||
let previousValue = await initialValue; | ||
for (const p of iter) { | ||
const t = await p; | ||
const nextValue = await fnReduce(previousValue, t, index); | ||
previousValue = nextValue; | ||
index += 1; | ||
} | ||
return previousValue; | ||
} | ||
exports.reduceAsync = reduceAsync; | ||
function reduceAsyncForAsyncIterator(i, fnReduce, initialValue) { | ||
var e_1, _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const iter = makeAsyncIterable(i[Symbol.asyncIterator]()); | ||
let index = 0; | ||
if (initialValue === undefined) { | ||
index = 1; | ||
const r = yield iter.next(); | ||
initialValue = r.value; | ||
} | ||
let previousValue = yield initialValue; | ||
try { | ||
for (var iter_1 = __asyncValues(iter), iter_1_1; iter_1_1 = yield iter_1.next(), !iter_1_1.done;) { | ||
const t = iter_1_1.value; | ||
const nextValue = yield fnReduce(previousValue, t, index); | ||
previousValue = nextValue; | ||
index += 1; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (iter_1_1 && !iter_1_1.done && (_a = iter_1.return)) yield _a.call(iter_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return previousValue; | ||
}); | ||
async function reduceAsyncForAsyncIterator(i, fnReduce, initialValue) { | ||
const iter = makeAsyncIterable(i[Symbol.asyncIterator]()); | ||
let index = 0; | ||
if (initialValue === undefined) { | ||
index = 1; | ||
const r = await iter.next(); | ||
initialValue = r.value; | ||
} | ||
let previousValue = await initialValue; | ||
for await (const t of iter) { | ||
const nextValue = await fnReduce(previousValue, t, index); | ||
previousValue = nextValue; | ||
index += 1; | ||
} | ||
return previousValue; | ||
} | ||
@@ -276,20 +228,14 @@ exports.reduceAsyncForAsyncIterator = reduceAsyncForAsyncIterator; | ||
function makeAsyncIterable(i) { | ||
function fromIterable(i) { | ||
return __asyncGenerator(this, arguments, function* fromIterable_1() { | ||
for (const v of i) { | ||
yield yield __await(v); | ||
} | ||
}); | ||
async function* fromIterable(i) { | ||
for (const v of i) { | ||
yield v; | ||
} | ||
} | ||
function fromIterator(i) { | ||
return __asyncGenerator(this, arguments, function* fromIterator_1() { | ||
for (let r = yield __await(i.next()); !r.done; r = yield __await(i.next())) { | ||
yield yield __await(r.value); | ||
} | ||
}); | ||
async function* fromIterator(i) { | ||
for (let r = await i.next(); !r.done; r = await i.next()) { | ||
yield r.value; | ||
} | ||
} | ||
function fromAsyncIterable(i) { | ||
return __asyncGenerator(this, arguments, function* fromAsyncIterable_1() { | ||
yield __await(yield* __asyncDelegator(__asyncValues(i))); | ||
}); | ||
async function* fromAsyncIterable(i) { | ||
yield* i; | ||
} | ||
@@ -296,0 +242,0 @@ return isAsyncIterable(i) ? (isAsyncIterableIterator(i) ? i : fromAsyncIterable(i)) : |
@@ -1,4 +0,4 @@ | ||
export declare type Maybe<T> = T | undefined; | ||
export declare type ThenArg<T> = T extends PromiseLike<infer U> ? U : T; | ||
export declare type IterableOfPromise<T> = IterableLike<Promise<Promise<T>>> | IterableLike<Promise<T>> | IterableLike<T>; | ||
export type Maybe<T> = T | undefined; | ||
export type ThenArg<T> = T extends PromiseLike<infer U> ? U : T; | ||
export type IterableOfPromise<T> = IterableLike<Promise<Promise<T>>> | IterableLike<Promise<T>> | IterableLike<T>; | ||
export interface IterableLike<T> { | ||
@@ -14,8 +14,8 @@ [Symbol.iterator](): Iterator<T> | IterableIterator<T>; | ||
} | ||
export declare type LazyIterable<T> = (() => IterableLike<T>) | IterableLike<T>; | ||
export declare type AsyncLazyIterable<T> = (() => AsyncIterableLike<T>) | AsyncIterableLike<T>; | ||
export declare type ChainFunction<T, U = T> = (i: IterableLike<T>) => IterableLike<U>; | ||
export declare type ReduceFunction<T, U = T> = (i: IterableLike<T>) => U; | ||
export declare type ReduceAsyncFunction<T, U = T> = (i: IterableLike<ThenArg<T>>) => U; | ||
export declare type ReduceAsyncFunctionForAsyncIterator<T, U = T> = (i: AsyncIterableLike<ThenArg<T>>) => U; | ||
export type LazyIterable<T> = (() => IterableLike<T>) | IterableLike<T>; | ||
export type AsyncLazyIterable<T> = (() => AsyncIterableLike<T>) | AsyncIterableLike<T>; | ||
export type ChainFunction<T, U = T> = (i: IterableLike<T>) => IterableLike<U>; | ||
export type ReduceFunction<T, U = T> = (i: IterableLike<T>) => U; | ||
export type ReduceAsyncFunction<T, U = T> = (i: IterableLike<ThenArg<T>>) => U; | ||
export type ReduceAsyncFunctionForAsyncIterator<T, U = T> = (i: AsyncIterableLike<ThenArg<T>>) => U; | ||
export interface Sequence<T> extends IterableLike<T> { | ||
@@ -22,0 +22,0 @@ next(): IteratorResult<T>; |
{ | ||
"name": "gensequence", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Small library to simplify working with Generators and Iterators in Javascript / Typescript", | ||
@@ -11,4 +11,5 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@tsconfig/node14": "^1.0.3", | ||
"@types/jest": "^28.1.8", | ||
"@types/node": "^18.7.14", | ||
"@types/node": "^18.11.11", | ||
"coveralls": "^3.1.1", | ||
@@ -18,3 +19,3 @@ "jest": "^28.1.3", | ||
"ts-jest": "^28.0.8", | ||
"typescript": "^4.8.2" | ||
"typescript": "^4.9.4" | ||
}, | ||
@@ -21,0 +22,0 @@ "scripts": { |
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
55420
8
1058