@proc7ts/push-iterator
Advanced tools
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var pushIterator = require('./push-iterator.cjs'); | ||
| var callThru = require('@proc7ts/call-thru'); | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator/call-thru | ||
| */ | ||
| /** | ||
| * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each | ||
| * element of the given iterable. | ||
| * | ||
| * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once, | ||
| * and iterates over results after that. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable containing elements to pass down the chain. | ||
| * | ||
| * @returns Next call for iterable call chain. | ||
| */ | ||
| function nextIterate(iterable) { | ||
| return callThru.nextCall((chain, pass) => chain.iterate(pass, iterable)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator/call-thru | ||
| */ | ||
| function thruIt(it, ...passes) { | ||
| const chain = (outcome, index) => { | ||
| const lastPass = index >= passes.length; | ||
| ++index; | ||
| const pass = index < passes.length ? passes[index] : () => { }; | ||
| const handleResult = (outcome, callResult, arg) => { | ||
| if (callThru.isNextCall(callResult)) { | ||
| callResult[callThru.NextCall__symbol](chain(outcome, index), pass); | ||
| } | ||
| else if (lastPass) { | ||
| outcome.push(pushIterator.overOne(arg)); | ||
| } | ||
| else { | ||
| chain(outcome, index).pass(pass, callResult); | ||
| } | ||
| }; | ||
| return ({ | ||
| call(fn, args) { | ||
| handleResult(outcome, fn(...args), args); | ||
| }, | ||
| pass(fn, arg) { | ||
| handleResult(outcome, fn(arg), arg); | ||
| }, | ||
| skip() { }, | ||
| iterate(fn, iterable) { | ||
| outcome.push(pushIterator.flatMapIt(iterable, item => { | ||
| const itemOutcome = []; | ||
| handleResult(itemOutcome, fn(item), item); | ||
| return pushIterator.flatMapArray(itemOutcome); | ||
| })); | ||
| }, | ||
| }); | ||
| }; | ||
| const finalOutcome = []; | ||
| chain(finalOutcome, 0).iterate(passes[0], it); | ||
| return pushIterator.flatMapArray(finalOutcome); | ||
| } | ||
| exports.nextIterate = nextIterate; | ||
| exports.thruIt = thruIt; | ||
| //# sourceMappingURL=push-iterator.call-thru.cjs.map |
| {"version":3,"file":"push-iterator.call-thru.cjs","sources":["../src/call-thru/next-iterate.ts","../src/call-thru/thru-it.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { NextCall, nextCall } from '@proc7ts/call-thru';\nimport type { IterableCallChain } from './iterable-call-chain';\n\n/**\n * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each\n * element of the given iterable.\n *\n * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once,\n * and iterates over results after that.\n *\n * @typeParam T Iterated elements type.\n * @param iterable An iterable containing elements to pass down the chain.\n *\n * @returns Next call for iterable call chain.\n */\nexport function nextIterate<T>(iterable: Iterable<T>): NextCall<IterableCallChain, [T], T> {\n return nextCall((chain, pass) => chain.iterate(pass, iterable));\n}\n","/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { isNextCall, NextCall__symbol } from '@proc7ts/call-thru';\nimport { overOne } from '../construction';\nimport type { PushIterable } from '../push-iterable';\nimport { flatMapArray, flatMapIt } from '../transformation';\nimport type { IterableCallChain } from './iterable-call-chain';\n\ntype Args<TReturn> = IterableCallChain.Args<TReturn>;\ntype Out<TReturn> = IterableCallChain.Out<TReturn>;\n\n/**\n * Passes each element of the given iterable trough the {@link IterableCallChain chain of transformation passes}.\n *\n * The passes are preformed by `@proc7ts/call-thru`.\n *\n * @returns An push iterable of transformed elements.\n */\nexport function thruIt<\n T, TReturn1\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n): PushIterable<Out<TReturn1>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n): PushIterable<Out<TReturn2>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n): PushIterable<Out<TReturn3>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n TArgs13 extends Args<TReturn12>, TReturn13,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n pass13: (this: void, ...args: TArgs13) => TReturn13,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<T, TReturn>(\n it: Iterable<T>,\n ...passes: ((...args: any[]) => any)[]\n): PushIterable<TReturn> {\n\n const chain = (outcome: PushIterable<any>[], index: number): IterableCallChain => {\n\n const lastPass = index >= passes.length;\n\n ++index;\n\n const pass = index < passes.length ? passes[index] : () => { /* empty pass */ };\n const handleResult = (outcome: PushIterable<any>[], callResult: any, arg: any): void => {\n if (isNextCall(callResult)) {\n callResult[NextCall__symbol](chain(outcome, index), pass);\n } else if (lastPass) {\n outcome.push(overOne(arg));\n } else {\n chain(outcome, index).pass(pass, callResult);\n }\n };\n\n return ({\n call<A extends any[]>(fn: (...args: A) => any, args: A): void {\n handleResult(outcome, fn(...args), args);\n },\n pass<A>(fn: (arg: A) => any, arg: A): void {\n handleResult(outcome, fn(arg), arg);\n },\n skip() {/* skip item */},\n iterate<I>(fn: (this: void, arg: I) => void, iterable: Iterable<I>): void {\n outcome.push(flatMapIt(\n iterable,\n item => {\n\n const itemOutcome: PushIterable<any>[] = [];\n\n handleResult(itemOutcome, fn(item), item);\n\n return flatMapArray(itemOutcome);\n },\n ));\n },\n });\n };\n\n const finalOutcome: PushIterable<any>[] = [];\n\n chain(finalOutcome, 0).iterate(passes[0], it);\n\n return flatMapArray<TReturn>(finalOutcome);\n}\n"],"names":["nextCall","isNextCall","NextCall__symbol","overOne","flatMapIt","flatMapArray"],"mappings":";;;;;;;AAAA;;;;AAOA;;;;;;;;;;;;SAYgB,WAAW,CAAI,QAAqB;IAClD,OAAOA,iBAAQ,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClE;;ACrBA;;;;SA2QgB,MAAM,CAClB,EAAe,EACf,GAAG,MAAmC;IAGxC,MAAM,KAAK,GAAG,CAAC,OAA4B,EAAE,KAAa;QAExD,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC;QAExC,EAAE,KAAK,CAAC;QAER,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAA0B,CAAC;QAChF,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,UAAe,EAAE,GAAQ;YAC3E,IAAIC,mBAAU,CAAC,UAAU,CAAC,EAAE;gBAC1B,UAAU,CAACC,yBAAgB,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aAC3D;iBAAM,IAAI,QAAQ,EAAE;gBACnB,OAAO,CAAC,IAAI,CAACC,oBAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5B;iBAAM;gBACL,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;QAEF,QAAQ;YACN,IAAI,CAAkB,EAAuB,EAAE,IAAO;gBACpD,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1C;YACD,IAAI,CAAI,EAAmB,EAAE,GAAM;gBACjC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;aACrC;YACD,IAAI,MAAoB;YACxB,OAAO,CAAI,EAAgC,EAAE,QAAqB;gBAChE,OAAO,CAAC,IAAI,CAACC,sBAAS,CAClB,QAAQ,EACR,IAAI;oBAEF,MAAM,WAAW,GAAwB,EAAE,CAAC;oBAE5C,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;oBAE1C,OAAOC,yBAAY,CAAC,WAAW,CAAC,CAAC;iBAClC,CACJ,CAAC,CAAC;aACJ;SACF,EAAE;KACJ,CAAC;IAEF,MAAM,YAAY,GAAwB,EAAE,CAAC;IAE7C,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE9C,OAAOA,yBAAY,CAAU,YAAY,CAAC,CAAC;AAC7C;;;;;"} |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| /** | ||
| * A key of {@link PushIterable} iteration method. | ||
| */ | ||
| const PushIterator__symbol = ( /*#__PURE__*/Symbol('push-iterator')); | ||
| function isPushIterable(iterable) { | ||
| return !!iterable[PushIterator__symbol]; | ||
| } | ||
| function iteratorOf(iterable) { | ||
| return iterable[Symbol.iterator](); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a push iterable implementation. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterate A function iterating over iterable elements conforming to {@link PushIterable.Iterate} requirements. | ||
| * | ||
| * @returns New push iterable instance performing iteration by `forNext` function. | ||
| */ | ||
| function makePushIterable(iterate) { | ||
| return { | ||
| [Symbol.iterator]: PushIterable$iterator, | ||
| [PushIterator__symbol]: iterate, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterable$iterator() { | ||
| return this[PushIterator__symbol](); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given push iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * Calling this function is the same as calling `!iterable[PushIterator__symbol](accept).isOver()`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable A push iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns `true` if there are more elements to iterate, or `false` otherwise. The former is possible only when | ||
| * iteration suspended, i.e. `accept` returned `true`. | ||
| */ | ||
| function pushIterated(iterable, accept) { | ||
| return !iterable[PushIterator__symbol](accept).isOver(); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a push iterator implementation. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param forNext A function iterating over elements conforming to push iteration protocol. | ||
| * | ||
| * @returns New push iterator instance performing iteration by `forNext` function. | ||
| */ | ||
| function makePushIterator(forNext) { | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| } | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: PushIterator$next, | ||
| isOver: () => over, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$iterator() { | ||
| return this; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$next() { | ||
| for (;;) { | ||
| let result; | ||
| const over = !pushIterated(this, value => { | ||
| result = { value }; | ||
| return true; | ||
| }); | ||
| if (result) { | ||
| return result; | ||
| } | ||
| if (over) { | ||
| return { done: true }; | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$noNext() { | ||
| return { done: true }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$dontIterate(_accept) { | ||
| /* do not iterate */ | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| const emptyPushIterator = { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](_accept) { | ||
| return this; | ||
| }, | ||
| next: () => ({ done: true }), | ||
| isOver: () => true, | ||
| }; | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over the head elements of the given push iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * Calling this function is the same as calling `iterable[PushIterator__symbol](accept)`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable A push iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns A push iterator instance representing the tail of the given iterable. This iterator can be used to continue | ||
| * iteration with, unless `accept` returned `false`. In the latter case the further iteration won't be possible. | ||
| */ | ||
| function pushHead(iterable, accept) { | ||
| return iterable[PushIterator__symbol](accept); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function indexedItemOf(indexed, index) { | ||
| return indexed.item(index); // The index is always valid. | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverIndexed(indexed, elementOf) { | ||
| return accept => { | ||
| let i = 0; | ||
| const forNext = (accept) => { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| for (;;) { | ||
| const goOn = accept(elementOf(indexed, i++)); | ||
| if (i >= indexed.length || goOn === false) { | ||
| return false; | ||
| } | ||
| if (goOn === true) { | ||
| return true; | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return emptyPushIterator; | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| if (i < indexed.length) { | ||
| return { value: elementOf(indexed, i++) }; | ||
| } | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function arrayElementOf(array, index) { | ||
| return array[index]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverArray(array) { | ||
| return iterateOverIndexed(array, arrayElementOf); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of array-like structure. | ||
| * | ||
| * @typeParam T Array elements type. | ||
| * @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc. | ||
| * | ||
| * @returns New push iterable over array elements. | ||
| */ | ||
| function overArray(array) { | ||
| return makePushIterable(iterateOverArray(array)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * In contrast to {@link pushIterated} function, this one accepts any iterable instance. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns `true` if there are more elements to iterate, or `false` otherwise. The former is possible only when | ||
| * iteration suspended, i.e. `accept` returned `true`. | ||
| */ | ||
| function itsIterated(iterable, accept) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushIterated(iterable, accept); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| if (isPushIterable(it)) { | ||
| return pushIterated(it, accept); | ||
| } | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const status = accept(next.value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Performs the given `action` for each element of the given `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable of elements to perform actions on. | ||
| * @param action An action to perform on each iterable element. This is a function accepting an element as its only | ||
| * parameter. | ||
| */ | ||
| function itsEach(iterable, action) { | ||
| itsIterated(iterable, element => { action(element); }); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * @internal | ||
| */ | ||
| const itsElements$defaultConverter = (element) => element; | ||
| function itsElements(source, convert = itsElements$defaultConverter) { | ||
| if (isPushIterable(source)) { | ||
| return pushedElements(source, convert); | ||
| } | ||
| const it = iteratorOf(source); | ||
| return isPushIterable(it) ? pushedElements(it, convert) : Array.from(source, convert); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedElements(it, convert) { | ||
| const result = []; | ||
| pushIterated(it, element => { result.push(convert(element)); }); | ||
| return result; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Checks whether the given `iterable` is empty. | ||
| * | ||
| * @param iterable An iterable or push iterable to check for elements. | ||
| * | ||
| * @return `true` if the given iterable contains at least one element, or `false` otherwise. | ||
| */ | ||
| function itsEmpty(iterable) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushedEmpty(iterable); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? pushedEmpty(it) : !!it.next().done; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedEmpty(it) { | ||
| let isEmpty = true; | ||
| pushIterated(it, _element /* Unused parameter to prevent deoptimization */ => isEmpty = false); | ||
| return isEmpty; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Tests whether all elements of the given `iterable` pass the test implemented by the provided function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to test elements of. | ||
| * @param test A predicate function to test each element. Returns `true` to continue tests, or `false` to stop it | ||
| * and return `false` from the method call. It accepts the tested element as the only parameter. | ||
| * | ||
| * @returns `true` if the `test` function returned a truthy value for every element, or `false` otherwise. | ||
| * Returns `true` for empty iterable. | ||
| */ | ||
| function itsEvery(iterable, test) { | ||
| let allMatch = true; | ||
| itsIterated(iterable, element => { | ||
| allMatch = !!test(element); | ||
| if (!allMatch) { | ||
| return false; | ||
| } | ||
| return; | ||
| }); | ||
| return allMatch; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Searches for the value in `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @typeParam TFound Found value type. | ||
| * @param iterable An iterable to extract element from. | ||
| * @param search A function extracting the value from elements. It is called for each iterated element until the value | ||
| * found. Accepts element as the only parameter, and returns extracted value. If returns `false` or `undefined` the | ||
| * search continues from the next element. | ||
| * | ||
| * @return Either found value or `undefined`. | ||
| */ | ||
| function itsFind(iterable, search) { | ||
| let find; | ||
| itsIterated(iterable, element => { | ||
| const result = search(element); | ||
| if (result !== false && result !== undefined) { | ||
| find = result; | ||
| return true; | ||
| } | ||
| return; | ||
| }); | ||
| return find; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Extracts the first element of the given `iterable`, if any. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to extract element from. | ||
| * | ||
| * @return Either the first element, or `undefined` if the given `iterable` is empty. | ||
| */ | ||
| function itsFirst(iterable) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushedFirst(iterable); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? pushedFirst(it) : rawFirst(it); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedFirst(it) { | ||
| let first; | ||
| pushIterated(it, element => { | ||
| first = element; | ||
| return false; | ||
| }); | ||
| return first; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawFirst(it) { | ||
| const result = it.next(); | ||
| return result.done ? undefined : result.value; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function toPushIterator(it, forNext) { | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if ((over = !!accept && !forNext(accept))) { | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| const res = it.next(); | ||
| if (res.done) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| } | ||
| return res; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next() { | ||
| return next(); | ||
| }, | ||
| isOver: () => over, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawIteratorPusher(it) { | ||
| return accept => { | ||
| for (;;) { | ||
| const res = it.next(); | ||
| if (res.done) { | ||
| return false; | ||
| } | ||
| const status = accept(res.value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * In contrast to {@link pushHead} function, this one accepts any iterable instance. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns A push iterator instance representing the tail of the given iterable. This iterator can be used to continue | ||
| * iteration with, unless `accept` returned `false`. In the latter case the further iteration won't be possible. | ||
| */ | ||
| function itsHead(iterable, accept) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushHead(iterable, accept); | ||
| } | ||
| if (Array.isArray(iterable)) { | ||
| return arrayHead(iterable, accept); | ||
| } | ||
| return rawIterableHead(iterable, accept); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function arrayHead(array, accept) { | ||
| return array.length ? iterateOverArray(array)(accept) : emptyPushIterator; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawIterableHead(iterable, accept) { | ||
| const it = iteratorOf(iterable); | ||
| if (isPushIterable(it)) { | ||
| return pushHead(it, accept); | ||
| } | ||
| const forEach = rawIteratorPusher(it); | ||
| return forEach(accept) ? toPushIterator(it, forEach) : emptyPushIterator; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Starts iteration over the given `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable or push iterable to iterate over. | ||
| * | ||
| * @return A push iterator iterating over the given iterable. | ||
| */ | ||
| function itsIterator(iterable) { | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? it : toPushIterator(it, rawIteratorPusher(it)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Extracts the first element matching the given condition from `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to extract element from. | ||
| * @param test A predicate function to test elements. Returns truthy value for matching one. It accepts the tested | ||
| * element as the only parameter. | ||
| * | ||
| * @return Either the matching element, or `undefined` if no elements match. | ||
| */ | ||
| function itsMatch(iterable, test) { | ||
| let match; | ||
| itsIterated(iterable, element => { | ||
| if (test(element)) { | ||
| match = element; | ||
| return true; | ||
| } | ||
| return; | ||
| }); | ||
| return match; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Applies a function against an accumulator and each element of the given `iterable` to reduce elements to a single | ||
| * value. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @typeParam TResult A type of reduced value. | ||
| * @param iterable An iterable to reduce values of. | ||
| * @param reducer A function to apply the value returned from the previous `reducer` call and to each element. | ||
| * @param initialValue Initial value passed to the first `reducer` call. | ||
| * | ||
| * @return Reduced value returned from the last `reducer` call, or `initialValue` if there is no elements in the given | ||
| * `iterable`. | ||
| */ | ||
| function itsReduction(iterable, reducer, initialValue) { | ||
| let reduced = initialValue; | ||
| itsIterated(iterable, element => { reduced = reducer(reduced, element); }); | ||
| return reduced; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Tests whether at least one element of the given `iterable` passes the test implemented by the provided function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to test elements of. | ||
| * @param test A predicate function to test each element. Returns `false` to continue tests, or `true` to stop it | ||
| * and return `true` from the method call. It accepts the tested element as the only parameter. | ||
| * | ||
| * @returns `true` if the callback function returned a truthy value for at least one element in the array, or `false` | ||
| * otherwise. Returns `false` for empty iterable. | ||
| */ | ||
| function itsSome(iterable, test) { | ||
| let someMatches = false; | ||
| itsIterated(iterable, element => { | ||
| someMatches = !!test(element); | ||
| if (someMatches) { | ||
| return false; | ||
| } | ||
| return; | ||
| }); | ||
| return someMatches; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Returns a {@link PushIterator push iterable iterator} without elements. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * | ||
| * @returns Empty push iterable and push iterator instance. | ||
| */ | ||
| function overNone() { | ||
| return emptyPushIterator; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of iterator created by the given function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterate A function creating new iterator. | ||
| * | ||
| * @returns New push iterable over elements of created iterator. | ||
| */ | ||
| function overIterator(iterate) { | ||
| return makePushIterable(iterateOverRawIterator(iterate)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverRawIterator(iterate) { | ||
| return accept => { | ||
| const it = iterate(); | ||
| if (isPushIterable(it)) { | ||
| return it[PushIterator__symbol](accept); | ||
| } | ||
| const forNext = rawIteratorPusher(it); | ||
| return accept && !forNext(accept) ? overNone() : toPushIterator(it, forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of the given raw iterable. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate over elements of. | ||
| * | ||
| * @returns New push iterable over elements of the given `iterable`. | ||
| */ | ||
| function overIterable(iterable) { | ||
| return Array.isArray(iterable) | ||
| ? overArray(iterable) | ||
| : overIterator(() => iteratorOf(iterable)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of other iterables. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param sources Source iterables to iterate over elements of. | ||
| * | ||
| * @returns New push iterable over elements of the given `sources`. | ||
| */ | ||
| function overElementsOf(...sources) { | ||
| return sources.length > 1 | ||
| ? makePushIterable(iterateOverSubElements(sources)) | ||
| : (sources.length | ||
| ? overIterable(sources[0]) | ||
| : overNone()); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverSubElements(sources) { | ||
| return accept => { | ||
| let i = 0; | ||
| let src = sources[0]; | ||
| const forNext = (accept) => { | ||
| for (;;) { | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const srcTail = itsHead(src, element => status = accept(element)); | ||
| if (srcTail.isOver()) { | ||
| if (++i >= sources.length) { | ||
| return false; | ||
| } | ||
| src = sources[i]; | ||
| } | ||
| else { | ||
| src = srcTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over items of {@link IndexedItemList indexed list}. | ||
| * | ||
| * @typeParam T Indexed items type. | ||
| * @param indexed An indexed list of items. E.g. DOM `NodeList`. | ||
| * | ||
| * @returns New push iterable over list items. | ||
| */ | ||
| function overIndexed(indexed) { | ||
| return makePushIterable(iterateOverIndexed(indexed, indexedItemOf)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over one value. | ||
| * | ||
| * @typeParam T Iterated element value type. | ||
| * @param value A value to iterate over. | ||
| * | ||
| * @returns New push iterable over the given value. | ||
| */ | ||
| function overOne(value) { | ||
| return makePushIterable(iterateOverOneValue(value)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverOneValue(value) { | ||
| return accept => { | ||
| if (accept) { | ||
| accept(value); | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| if (over) { | ||
| return overNone(); | ||
| } | ||
| if (accept) { | ||
| over = true; | ||
| accept(value); | ||
| return overNone(); | ||
| } | ||
| return this; | ||
| }, | ||
| next() { | ||
| if (over) { | ||
| return { done: over }; | ||
| } | ||
| over = true; | ||
| return { value }; | ||
| }, | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over many values. | ||
| * | ||
| * @typeParam T Iterated elements value type. | ||
| * @param values Values to iterate over. | ||
| * | ||
| * @returns New push iterable over the given values. | ||
| */ | ||
| function overMany(...values) { | ||
| return values.length > 1 | ||
| ? overArray(values) | ||
| : (values.length | ||
| ? overOne(values[0]) | ||
| : overNone()); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of array-like structure in reverse order. | ||
| * | ||
| * @typeParam T Array elements type. | ||
| * @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc. | ||
| * | ||
| * @returns New push iterable over array elements in reverse order. | ||
| */ | ||
| function reverseArray(array) { | ||
| return makePushIterable(iterateOverArrayReversely(array)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverArrayReversely(array) { | ||
| return accept => { | ||
| let i = array.length - 1; | ||
| const forNext = (accept) => { | ||
| if (i < 0) { | ||
| return false; | ||
| } | ||
| for (;;) { | ||
| const status = accept(array[i--]); | ||
| if (i < 0) { | ||
| return false; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return true; | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| if (i < 0) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| } | ||
| return { value: array[i--] }; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over keys of the given object. | ||
| * | ||
| * A list of keys is constructed using `Reflect.ownKeys()`. | ||
| * | ||
| * @typeParam TObj Source object type. | ||
| * @param source An object to select keys from. | ||
| * | ||
| * @returns New push iterable over own object keys retrieved by `Reflect.ownKeys()`. | ||
| */ | ||
| function overKeys(source) { | ||
| return overArray(Reflect.ownKeys(source)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverFilteredIndexed(indexed, elementOf, test) { | ||
| return accept => { | ||
| let i = 0; | ||
| const forNext = (accept) => { | ||
| for (;;) { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| const value = elementOf(indexed, i++); | ||
| if (test(value)) { | ||
| const status = accept(value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| for (;;) { | ||
| if (i >= indexed.length) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| } | ||
| const value = elementOf(indexed, i++); | ||
| if (test(value)) { | ||
| return { value }; | ||
| } | ||
| } | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterArray(array, test) { | ||
| return makePushIterable(iterateOverFilteredIndexed(array, arrayElementOf, test)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterIndexed(array, test) { | ||
| return makePushIterable(iterateOverFilteredIndexed(array, indexedItemOf, test)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterIt(source, test) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? filterPusher(source, test) : filterRawPusher(source, test); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function filterPusher(source, test) { | ||
| return accept => { | ||
| const tail = pushHead(source, element => { | ||
| if (test(element)) { | ||
| return accept(element); | ||
| } | ||
| return; | ||
| }); | ||
| source = tail; | ||
| return !tail.isOver(); | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function filterRawPusher(source, test) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return filterPusher(it, test); | ||
| } | ||
| return accept => { | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const value = next.value; | ||
| if (test(value)) { | ||
| const status = accept(value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverFlattenedIndexed(indexed, elementsOf) { | ||
| return accept => { | ||
| let i = 0; | ||
| let subs; | ||
| const forNext = (accept) => { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| if (!subs) { | ||
| subs = elementsOf(indexed, i); | ||
| } | ||
| for (;;) { | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| if (subsTail.isOver()) { | ||
| if (++i >= indexed.length) { | ||
| return false; | ||
| } | ||
| subs = elementsOf(indexed, i); | ||
| } | ||
| else { | ||
| subs = subsTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapArray(array, convert) { | ||
| return makePushIterable(iterateOverFlattenedIndexed(array, convert | ||
| ? (array, index) => convert(array[index]) | ||
| : flatMapArray$defaultElementOf)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapArray$defaultElementOf(array, index) { | ||
| return array[index]; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapIndexed(indexed, convert) { | ||
| return makePushIterable(iterateOverFlattenedIndexed(indexed, convert | ||
| ? (indexed, index) => convert(indexed.item(index)) | ||
| : flatMapIndexed$defaultElementOf)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapIndexed$defaultElementOf(indexed, index) { | ||
| return indexed.item(index); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapIt(source, convert = flatMapIt$defaultConverter) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? flatMapPusher(source, convert) : flatMapRawPusher(source, convert); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapPusher(source, convert) { | ||
| let subs; | ||
| let lastSrc = false; | ||
| return accept => { | ||
| for (;;) { | ||
| while (!subs) { | ||
| const sourceTail = pushHead(source, src => { | ||
| subs = convert(src); | ||
| return true; | ||
| }); | ||
| source = sourceTail; | ||
| if (sourceTail.isOver()) { | ||
| if (!subs) { | ||
| return false; | ||
| } | ||
| lastSrc = true; | ||
| } | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| if (subsTail.isOver()) { | ||
| subs = undefined; | ||
| if (lastSrc) { | ||
| return false; | ||
| } | ||
| } | ||
| else { | ||
| subs = subsTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapRawPusher(source, convert) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return flatMapPusher(it, convert); | ||
| } | ||
| let subs; | ||
| return accept => { | ||
| for (;;) { | ||
| if (!subs) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| subs = convert(next.value); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| subs = subsTail.isOver() ? undefined : subsTail; | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapIt$defaultConverter(element) { | ||
| return element; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every element of the | ||
| * given `array`. | ||
| * | ||
| * @typeParam TSrc A type of array elements. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param array A source array-like instance. | ||
| * @param convert A function that produces an element of new iterable, taking array element as the only parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapArray(array, convert) { | ||
| return makePushIterable(iterateOverIndexed(array, (array, index) => convert(array[index]))); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every item of the | ||
| * given indexed list. | ||
| * | ||
| * @typeParam TSrc A type of indexed list items. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param indexed A source indexed items list. | ||
| * @param convert A function that produces an element of new iterable, taking list item as the only parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapIndexed(indexed, convert) { | ||
| return makePushIterable(iterateOverIndexed(indexed, (list, index) => convert(list.item(index) /* The index is always valid */))); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every element of the | ||
| * `source` iterable. | ||
| * | ||
| * @typeParam TSrc A type of source elements. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param source A source iterable. | ||
| * @param convert A function that produces an element of the new iterable, taking the source element as the only | ||
| * parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapIt(source, convert) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? mapPusher(source, convert) : mapRawPusher(source, convert); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function mapPusher(source, convert) { | ||
| return accept => { | ||
| const tail = pushHead(source, element => accept(convert(element))); | ||
| source = tail; | ||
| return !tail.isOver(); | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function mapRawPusher(source, convert) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return mapPusher(it, convert); | ||
| } | ||
| return accept => { | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const status = accept(convert(next.value)); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over the property key/value entries of the given object. | ||
| * | ||
| * A list of keys is constructed using `Reflect.ownKeys()`. | ||
| * | ||
| * @typeParam TObj Object type. | ||
| * | ||
| * @param source An object to select keys and values from. | ||
| * | ||
| * @returns New push iterable of object property entries. | ||
| */ | ||
| function overEntries(source) { | ||
| return mapIt(overKeys(source), key => [key, source[key]]); | ||
| } | ||
| exports.PushIterator__symbol = PushIterator__symbol; | ||
| exports.filterArray = filterArray; | ||
| exports.filterIndexed = filterIndexed; | ||
| exports.filterIt = filterIt; | ||
| exports.flatMapArray = flatMapArray; | ||
| exports.flatMapIndexed = flatMapIndexed; | ||
| exports.flatMapIt = flatMapIt; | ||
| exports.isPushIterable = isPushIterable; | ||
| exports.iteratorOf = iteratorOf; | ||
| exports.itsEach = itsEach; | ||
| exports.itsElements = itsElements; | ||
| exports.itsEmpty = itsEmpty; | ||
| exports.itsEvery = itsEvery; | ||
| exports.itsFind = itsFind; | ||
| exports.itsFirst = itsFirst; | ||
| exports.itsHead = itsHead; | ||
| exports.itsIterated = itsIterated; | ||
| exports.itsIterator = itsIterator; | ||
| exports.itsMatch = itsMatch; | ||
| exports.itsReduction = itsReduction; | ||
| exports.itsSome = itsSome; | ||
| exports.makePushIterable = makePushIterable; | ||
| exports.makePushIterator = makePushIterator; | ||
| exports.mapArray = mapArray; | ||
| exports.mapIndexed = mapIndexed; | ||
| exports.mapIt = mapIt; | ||
| exports.overArray = overArray; | ||
| exports.overElementsOf = overElementsOf; | ||
| exports.overEntries = overEntries; | ||
| exports.overIndexed = overIndexed; | ||
| exports.overIterable = overIterable; | ||
| exports.overIterator = overIterator; | ||
| exports.overKeys = overKeys; | ||
| exports.overMany = overMany; | ||
| exports.overNone = overNone; | ||
| exports.overOne = overOne; | ||
| exports.pushHead = pushHead; | ||
| exports.pushIterated = pushIterated; | ||
| exports.reverseArray = reverseArray; | ||
| //# sourceMappingURL=push-iterator.cjs.map |
Sorry, the diff of this file is too big to display
| { | ||
| "main": "../dist/push-iterator.call-thru.js", | ||
| "module": "../dist/push-iterator.call-thru.mjs", | ||
| "main": "../dist/push-iterator.call-thru.cjs", | ||
| "module": "../dist/push-iterator.call-thru.js", | ||
| "types": "index.d.ts" | ||
| } |
@@ -1,8 +0,4 @@ | ||
| 'use strict'; | ||
| import { flatMapIt, flatMapArray, overOne } from './push-iterator.js'; | ||
| import { nextCall, isNextCall, NextCall__symbol } from '@proc7ts/call-thru'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var pushIterator = require('./push-iterator.js'); | ||
| var callThru = require('@proc7ts/call-thru'); | ||
| /** | ||
@@ -25,3 +21,3 @@ * @packageDocumentation | ||
| function nextIterate(iterable) { | ||
| return callThru.nextCall((chain, pass) => chain.iterate(pass, iterable)); | ||
| return nextCall((chain, pass) => chain.iterate(pass, iterable)); | ||
| } | ||
@@ -39,7 +35,7 @@ | ||
| const handleResult = (outcome, callResult, arg) => { | ||
| if (callThru.isNextCall(callResult)) { | ||
| callResult[callThru.NextCall__symbol](chain(outcome, index), pass); | ||
| if (isNextCall(callResult)) { | ||
| callResult[NextCall__symbol](chain(outcome, index), pass); | ||
| } | ||
| else if (lastPass) { | ||
| outcome.push(pushIterator.overOne(arg)); | ||
| outcome.push(overOne(arg)); | ||
| } | ||
@@ -59,6 +55,6 @@ else { | ||
| iterate(fn, iterable) { | ||
| outcome.push(pushIterator.flatMapIt(iterable, item => { | ||
| outcome.push(flatMapIt(iterable, item => { | ||
| const itemOutcome = []; | ||
| handleResult(itemOutcome, fn(item), item); | ||
| return pushIterator.flatMapArray(itemOutcome); | ||
| return flatMapArray(itemOutcome); | ||
| })); | ||
@@ -70,7 +66,6 @@ }, | ||
| chain(finalOutcome, 0).iterate(passes[0], it); | ||
| return pushIterator.flatMapArray(finalOutcome); | ||
| return flatMapArray(finalOutcome); | ||
| } | ||
| exports.nextIterate = nextIterate; | ||
| exports.thruIt = thruIt; | ||
| export { nextIterate, thruIt }; | ||
| //# sourceMappingURL=push-iterator.call-thru.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"push-iterator.call-thru.js","sources":["../src/call-thru/next-iterate.ts","../src/call-thru/thru-it.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { NextCall, nextCall } from '@proc7ts/call-thru';\nimport type { IterableCallChain } from './iterable-call-chain';\n\n/**\n * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each\n * element of the given iterable.\n *\n * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once,\n * and iterates over results after that.\n *\n * @typeParam T Iterated elements type.\n * @param iterable An iterable containing elements to pass down the chain.\n *\n * @returns Next call for iterable call chain.\n */\nexport function nextIterate<T>(iterable: Iterable<T>): NextCall<IterableCallChain, [T], T> {\n return nextCall((chain, pass) => chain.iterate(pass, iterable));\n}\n","/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { isNextCall, NextCall__symbol } from '@proc7ts/call-thru';\nimport { overOne } from '../construction';\nimport type { PushIterable } from '../push-iterable';\nimport { flatMapArray, flatMapIt } from '../transformation';\nimport type { IterableCallChain } from './iterable-call-chain';\n\ntype Args<TReturn> = IterableCallChain.Args<TReturn>;\ntype Out<TReturn> = IterableCallChain.Out<TReturn>;\n\n/**\n * Passes each element of the given iterable trough the {@link IterableCallChain chain of transformation passes}.\n *\n * The passes are preformed by `@proc7ts/call-thru`.\n *\n * @returns An push iterable of transformed elements.\n */\nexport function thruIt<\n T, TReturn1\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n): PushIterable<Out<TReturn1>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n): PushIterable<Out<TReturn2>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n): PushIterable<Out<TReturn3>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n TArgs13 extends Args<TReturn12>, TReturn13,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n pass13: (this: void, ...args: TArgs13) => TReturn13,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<T, TReturn>(\n it: Iterable<T>,\n ...passes: ((...args: any[]) => any)[]\n): PushIterable<TReturn> {\n\n const chain = (outcome: PushIterable<any>[], index: number): IterableCallChain => {\n\n const lastPass = index >= passes.length;\n\n ++index;\n\n const pass = index < passes.length ? passes[index] : () => { /* empty pass */ };\n const handleResult = (outcome: PushIterable<any>[], callResult: any, arg: any): void => {\n if (isNextCall(callResult)) {\n callResult[NextCall__symbol](chain(outcome, index), pass);\n } else if (lastPass) {\n outcome.push(overOne(arg));\n } else {\n chain(outcome, index).pass(pass, callResult);\n }\n };\n\n return ({\n call<A extends any[]>(fn: (...args: A) => any, args: A): void {\n handleResult(outcome, fn(...args), args);\n },\n pass<A>(fn: (arg: A) => any, arg: A): void {\n handleResult(outcome, fn(arg), arg);\n },\n skip() {/* skip item */},\n iterate<I>(fn: (this: void, arg: I) => void, iterable: Iterable<I>): void {\n outcome.push(flatMapIt(\n iterable,\n item => {\n\n const itemOutcome: PushIterable<any>[] = [];\n\n handleResult(itemOutcome, fn(item), item);\n\n return flatMapArray(itemOutcome);\n },\n ));\n },\n });\n };\n\n const finalOutcome: PushIterable<any>[] = [];\n\n chain(finalOutcome, 0).iterate(passes[0], it);\n\n return flatMapArray<TReturn>(finalOutcome);\n}\n"],"names":["nextCall","isNextCall","NextCall__symbol","overOne","flatMapIt","flatMapArray"],"mappings":";;;;;;;AAAA;;;;AAOA;;;;;;;;;;;;SAYgB,WAAW,CAAI,QAAqB;IAClD,OAAOA,iBAAQ,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClE;;ACrBA;;;;SA2QgB,MAAM,CAClB,EAAe,EACf,GAAG,MAAmC;IAGxC,MAAM,KAAK,GAAG,CAAC,OAA4B,EAAE,KAAa;QAExD,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC;QAExC,EAAE,KAAK,CAAC;QAER,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAA0B,CAAC;QAChF,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,UAAe,EAAE,GAAQ;YAC3E,IAAIC,mBAAU,CAAC,UAAU,CAAC,EAAE;gBAC1B,UAAU,CAACC,yBAAgB,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aAC3D;iBAAM,IAAI,QAAQ,EAAE;gBACnB,OAAO,CAAC,IAAI,CAACC,oBAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5B;iBAAM;gBACL,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;QAEF,QAAQ;YACN,IAAI,CAAkB,EAAuB,EAAE,IAAO;gBACpD,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1C;YACD,IAAI,CAAI,EAAmB,EAAE,GAAM;gBACjC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;aACrC;YACD,IAAI,MAAoB;YACxB,OAAO,CAAI,EAAgC,EAAE,QAAqB;gBAChE,OAAO,CAAC,IAAI,CAACC,sBAAS,CAClB,QAAQ,EACR,IAAI;oBAEF,MAAM,WAAW,GAAwB,EAAE,CAAC;oBAE5C,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;oBAE1C,OAAOC,yBAAY,CAAC,WAAW,CAAC,CAAC;iBAClC,CACJ,CAAC,CAAC;aACJ;SACF,EAAE;KACJ,CAAC;IAEF,MAAM,YAAY,GAAwB,EAAE,CAAC;IAE7C,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE9C,OAAOA,yBAAY,CAAU,YAAY,CAAC,CAAC;AAC7C;;;;;"} | ||
| {"version":3,"file":"push-iterator.call-thru.js","sources":["../src/call-thru/next-iterate.ts","../src/call-thru/thru-it.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { NextCall, nextCall } from '@proc7ts/call-thru';\nimport type { IterableCallChain } from './iterable-call-chain';\n\n/**\n * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each\n * element of the given iterable.\n *\n * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once,\n * and iterates over results after that.\n *\n * @typeParam T Iterated elements type.\n * @param iterable An iterable containing elements to pass down the chain.\n *\n * @returns Next call for iterable call chain.\n */\nexport function nextIterate<T>(iterable: Iterable<T>): NextCall<IterableCallChain, [T], T> {\n return nextCall((chain, pass) => chain.iterate(pass, iterable));\n}\n","/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { isNextCall, NextCall__symbol } from '@proc7ts/call-thru';\nimport { overOne } from '../construction';\nimport type { PushIterable } from '../push-iterable';\nimport { flatMapArray, flatMapIt } from '../transformation';\nimport type { IterableCallChain } from './iterable-call-chain';\n\ntype Args<TReturn> = IterableCallChain.Args<TReturn>;\ntype Out<TReturn> = IterableCallChain.Out<TReturn>;\n\n/**\n * Passes each element of the given iterable trough the {@link IterableCallChain chain of transformation passes}.\n *\n * The passes are preformed by `@proc7ts/call-thru`.\n *\n * @returns An push iterable of transformed elements.\n */\nexport function thruIt<\n T, TReturn1\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n): PushIterable<Out<TReturn1>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n): PushIterable<Out<TReturn2>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n): PushIterable<Out<TReturn3>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n TArgs13 extends Args<TReturn12>, TReturn13,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n pass13: (this: void, ...args: TArgs13) => TReturn13,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<T, TReturn>(\n it: Iterable<T>,\n ...passes: ((...args: any[]) => any)[]\n): PushIterable<TReturn> {\n\n const chain = (outcome: PushIterable<any>[], index: number): IterableCallChain => {\n\n const lastPass = index >= passes.length;\n\n ++index;\n\n const pass = index < passes.length ? passes[index] : () => { /* empty pass */ };\n const handleResult = (outcome: PushIterable<any>[], callResult: any, arg: any): void => {\n if (isNextCall(callResult)) {\n callResult[NextCall__symbol](chain(outcome, index), pass);\n } else if (lastPass) {\n outcome.push(overOne(arg));\n } else {\n chain(outcome, index).pass(pass, callResult);\n }\n };\n\n return ({\n call<A extends any[]>(fn: (...args: A) => any, args: A): void {\n handleResult(outcome, fn(...args), args);\n },\n pass<A>(fn: (arg: A) => any, arg: A): void {\n handleResult(outcome, fn(arg), arg);\n },\n skip() {/* skip item */},\n iterate<I>(fn: (this: void, arg: I) => void, iterable: Iterable<I>): void {\n outcome.push(flatMapIt(\n iterable,\n item => {\n\n const itemOutcome: PushIterable<any>[] = [];\n\n handleResult(itemOutcome, fn(item), item);\n\n return flatMapArray(itemOutcome);\n },\n ));\n },\n });\n };\n\n const finalOutcome: PushIterable<any>[] = [];\n\n chain(finalOutcome, 0).iterate(passes[0], it);\n\n return flatMapArray<TReturn>(finalOutcome);\n}\n"],"names":[],"mappings":";;;AAAA;;;;AAOA;;;;;;;;;;;;SAYgB,WAAW,CAAI,QAAqB;IAClD,OAAO,QAAQ,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClE;;ACrBA;;;;SA2QgB,MAAM,CAClB,EAAe,EACf,GAAG,MAAmC;IAGxC,MAAM,KAAK,GAAG,CAAC,OAA4B,EAAE,KAAa;QAExD,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC;QAExC,EAAE,KAAK,CAAC;QAER,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAA0B,CAAC;QAChF,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,UAAe,EAAE,GAAQ;YAC3E,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;gBAC1B,UAAU,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aAC3D;iBAAM,IAAI,QAAQ,EAAE;gBACnB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5B;iBAAM;gBACL,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;QAEF,QAAQ;YACN,IAAI,CAAkB,EAAuB,EAAE,IAAO;gBACpD,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1C;YACD,IAAI,CAAI,EAAmB,EAAE,GAAM;gBACjC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;aACrC;YACD,IAAI,MAAoB;YACxB,OAAO,CAAI,EAAgC,EAAE,QAAqB;gBAChE,OAAO,CAAC,IAAI,CAAC,SAAS,CAClB,QAAQ,EACR,IAAI;oBAEF,MAAM,WAAW,GAAwB,EAAE,CAAC;oBAE5C,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;oBAE1C,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC;iBAClC,CACJ,CAAC,CAAC;aACJ;SACF,EAAE;KACJ,CAAC;IAEF,MAAM,YAAY,GAAwB,EAAE,CAAC;IAE7C,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE9C,OAAO,YAAY,CAAU,YAAY,CAAC,CAAC;AAC7C;;;;"} |
@@ -1,5 +0,1 @@ | ||
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| /** | ||
@@ -1310,41 +1306,3 @@ * A key of {@link PushIterable} iteration method. | ||
| exports.PushIterator__symbol = PushIterator__symbol; | ||
| exports.filterArray = filterArray; | ||
| exports.filterIndexed = filterIndexed; | ||
| exports.filterIt = filterIt; | ||
| exports.flatMapArray = flatMapArray; | ||
| exports.flatMapIndexed = flatMapIndexed; | ||
| exports.flatMapIt = flatMapIt; | ||
| exports.isPushIterable = isPushIterable; | ||
| exports.iteratorOf = iteratorOf; | ||
| exports.itsEach = itsEach; | ||
| exports.itsElements = itsElements; | ||
| exports.itsEmpty = itsEmpty; | ||
| exports.itsEvery = itsEvery; | ||
| exports.itsFind = itsFind; | ||
| exports.itsFirst = itsFirst; | ||
| exports.itsHead = itsHead; | ||
| exports.itsIterated = itsIterated; | ||
| exports.itsIterator = itsIterator; | ||
| exports.itsMatch = itsMatch; | ||
| exports.itsReduction = itsReduction; | ||
| exports.itsSome = itsSome; | ||
| exports.makePushIterable = makePushIterable; | ||
| exports.makePushIterator = makePushIterator; | ||
| exports.mapArray = mapArray; | ||
| exports.mapIndexed = mapIndexed; | ||
| exports.mapIt = mapIt; | ||
| exports.overArray = overArray; | ||
| exports.overElementsOf = overElementsOf; | ||
| exports.overEntries = overEntries; | ||
| exports.overIndexed = overIndexed; | ||
| exports.overIterable = overIterable; | ||
| exports.overIterator = overIterator; | ||
| exports.overKeys = overKeys; | ||
| exports.overMany = overMany; | ||
| exports.overNone = overNone; | ||
| exports.overOne = overOne; | ||
| exports.pushHead = pushHead; | ||
| exports.pushIterated = pushIterated; | ||
| exports.reverseArray = reverseArray; | ||
| export { PushIterator__symbol, filterArray, filterIndexed, filterIt, flatMapArray, flatMapIndexed, flatMapIt, isPushIterable, iteratorOf, itsEach, itsElements, itsEmpty, itsEvery, itsFind, itsFirst, itsHead, itsIterated, itsIterator, itsMatch, itsReduction, itsSome, makePushIterable, makePushIterator, mapArray, mapIndexed, mapIt, overArray, overElementsOf, overEntries, overIndexed, overIterable, overIterator, overKeys, overMany, overNone, overOne, pushHead, pushIterated, reverseArray }; | ||
| //# sourceMappingURL=push-iterator.js.map |
+26
-25
| { | ||
| "name": "@proc7ts/push-iterator", | ||
| "version": "2.2.0", | ||
| "version": "2.3.0", | ||
| "description": "Push iteration protocol", | ||
@@ -21,54 +21,55 @@ "keywords": [ | ||
| }, | ||
| "main": "dist/push-iterator.js", | ||
| "module": "dist/push-iterator.mjs", | ||
| "type": "module", | ||
| "main": "dist/push-iterator.cjs", | ||
| "module": "dist/push-iterator.js", | ||
| "types": "index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/push-iterator.js", | ||
| "import": "./dist/push-iterator.mjs" | ||
| "require": "./dist/push-iterator.cjs", | ||
| "import": "./dist/push-iterator.js" | ||
| }, | ||
| "./call-thru": { | ||
| "require": "./dist/push-iterator.call-thru.js", | ||
| "import": "./dist/push-iterator.call-thru.mjs" | ||
| "require": "./dist/push-iterator.call-thru.cjs", | ||
| "import": "./dist/push-iterator.call-thru.js" | ||
| } | ||
| }, | ||
| "peerDependencies": { | ||
| "@proc7ts/call-thru": "^4.1.0" | ||
| "@proc7ts/call-thru": "^4.2.0" | ||
| }, | ||
| "dependencies": { | ||
| "@proc7ts/primitives": "^1.2.0" | ||
| "@proc7ts/primitives": "^1.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@proc7ts/call-thru": "^4.1.0", | ||
| "@proc7ts/call-thru": "^4.2.0", | ||
| "@proc7ts/eslint-config": "^2.0.5", | ||
| "@proc7ts/rollup-helpers": "^1.0.0", | ||
| "@rollup/plugin-commonjs": "^15.1.0", | ||
| "@rollup/plugin-node-resolve": "^9.0.0", | ||
| "@types/benchmark": "^1.0.33", | ||
| "@rollup/plugin-commonjs": "^16.0.0", | ||
| "@rollup/plugin-node-resolve": "^10.0.0", | ||
| "@types/benchmark": "^2.1.0", | ||
| "@types/jest": "^26.0.15", | ||
| "@types/node": "^12.12.62", | ||
| "@typescript-eslint/eslint-plugin": "^4.5.0", | ||
| "@typescript-eslint/parser": "^4.5.0", | ||
| "@typescript-eslint/eslint-plugin": "^4.7.0", | ||
| "@typescript-eslint/parser": "^4.7.0", | ||
| "benchmark": "^2.1.4", | ||
| "chalk": "^4.1.0", | ||
| "codecov": "^3.8.0", | ||
| "eslint": "^7.11.0", | ||
| "codecov": "^3.8.1", | ||
| "eslint": "^7.13.0", | ||
| "eslint-plugin-jest": "^24.1.0", | ||
| "gh-pages": "^3.1.0", | ||
| "jest": "^26.6.0", | ||
| "jest": "^26.6.3", | ||
| "jest-junit": "^12.0.0", | ||
| "rollup": "^2.32.1", | ||
| "rollup": "^2.33.1", | ||
| "rollup-plugin-sourcemaps": "^0.6.3", | ||
| "rollup-plugin-typescript2": "^0.28.0", | ||
| "run-z": "~1.4.0", | ||
| "shx": "^0.3.2", | ||
| "ts-jest": "^26.4.1", | ||
| "rollup-plugin-typescript2": "^0.29.0", | ||
| "run-z": "~1.5.1", | ||
| "shx": "^0.3.3", | ||
| "ts-jest": "^26.4.4", | ||
| "tslib": "^2.0.3", | ||
| "typedoc": "^0.19.0", | ||
| "typedoc-plugin-external-module-name": "^4.0.3", | ||
| "typescript": "^4.0.3" | ||
| "typescript": "^4.0.5" | ||
| }, | ||
| "scripts": { | ||
| "all": "run-z build,lint,test", | ||
| "benchmark": "run-z benchmark:build --then node --no-warnings --enable-source-maps ./target/benchmark.mjs", | ||
| "benchmark": "run-z benchmark:build --then node --no-warnings --enable-source-maps ./target/benchmark.js", | ||
| "benchmark:build": "run-z --then rollup --config ./rollup.benchmark.config.js", | ||
@@ -75,0 +76,0 @@ "benchmark:record": "run-z benchmark:build benchmark:record:node12 benchmark:record:node14", |
+1
-1
@@ -210,3 +210,3 @@ Push Iteration Protocol | ||
| [indexed list]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#IndexedItemList | ||
| [indexed list]: https://proc7ts.github.io/push-iterator/interfaces/@proc7ts_push-iterator.IndexedItemList.html | ||
| [filterIndexed]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#filterIndexed | ||
@@ -213,0 +213,0 @@ [flatMapIndexed]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#flatMapIndexed |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
| import { flatMapIt, flatMapArray, overOne } from './push-iterator.mjs'; | ||
| import { nextCall, isNextCall, NextCall__symbol } from '@proc7ts/call-thru'; | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator/call-thru | ||
| */ | ||
| /** | ||
| * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each | ||
| * element of the given iterable. | ||
| * | ||
| * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once, | ||
| * and iterates over results after that. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable containing elements to pass down the chain. | ||
| * | ||
| * @returns Next call for iterable call chain. | ||
| */ | ||
| function nextIterate(iterable) { | ||
| return nextCall((chain, pass) => chain.iterate(pass, iterable)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator/call-thru | ||
| */ | ||
| function thruIt(it, ...passes) { | ||
| const chain = (outcome, index) => { | ||
| const lastPass = index >= passes.length; | ||
| ++index; | ||
| const pass = index < passes.length ? passes[index] : () => { }; | ||
| const handleResult = (outcome, callResult, arg) => { | ||
| if (isNextCall(callResult)) { | ||
| callResult[NextCall__symbol](chain(outcome, index), pass); | ||
| } | ||
| else if (lastPass) { | ||
| outcome.push(overOne(arg)); | ||
| } | ||
| else { | ||
| chain(outcome, index).pass(pass, callResult); | ||
| } | ||
| }; | ||
| return ({ | ||
| call(fn, args) { | ||
| handleResult(outcome, fn(...args), args); | ||
| }, | ||
| pass(fn, arg) { | ||
| handleResult(outcome, fn(arg), arg); | ||
| }, | ||
| skip() { }, | ||
| iterate(fn, iterable) { | ||
| outcome.push(flatMapIt(iterable, item => { | ||
| const itemOutcome = []; | ||
| handleResult(itemOutcome, fn(item), item); | ||
| return flatMapArray(itemOutcome); | ||
| })); | ||
| }, | ||
| }); | ||
| }; | ||
| const finalOutcome = []; | ||
| chain(finalOutcome, 0).iterate(passes[0], it); | ||
| return flatMapArray(finalOutcome); | ||
| } | ||
| export { nextIterate, thruIt }; | ||
| //# sourceMappingURL=push-iterator.call-thru.mjs.map |
| {"version":3,"file":"push-iterator.call-thru.mjs","sources":["../src/call-thru/next-iterate.ts","../src/call-thru/thru-it.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { NextCall, nextCall } from '@proc7ts/call-thru';\nimport type { IterableCallChain } from './iterable-call-chain';\n\n/**\n * Creates a next call in {@link IterableCallChain iterable call chain} that performs the next passes for each\n * element of the given iterable.\n *\n * This call passes elements to the next call on demand, while the `nextEach()` one transforms them all at once,\n * and iterates over results after that.\n *\n * @typeParam T Iterated elements type.\n * @param iterable An iterable containing elements to pass down the chain.\n *\n * @returns Next call for iterable call chain.\n */\nexport function nextIterate<T>(iterable: Iterable<T>): NextCall<IterableCallChain, [T], T> {\n return nextCall((chain, pass) => chain.iterate(pass, iterable));\n}\n","/**\n * @packageDocumentation\n * @module @proc7ts/push-iterator/call-thru\n */\nimport { isNextCall, NextCall__symbol } from '@proc7ts/call-thru';\nimport { overOne } from '../construction';\nimport type { PushIterable } from '../push-iterable';\nimport { flatMapArray, flatMapIt } from '../transformation';\nimport type { IterableCallChain } from './iterable-call-chain';\n\ntype Args<TReturn> = IterableCallChain.Args<TReturn>;\ntype Out<TReturn> = IterableCallChain.Out<TReturn>;\n\n/**\n * Passes each element of the given iterable trough the {@link IterableCallChain chain of transformation passes}.\n *\n * The passes are preformed by `@proc7ts/call-thru`.\n *\n * @returns An push iterable of transformed elements.\n */\nexport function thruIt<\n T, TReturn1\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n): PushIterable<Out<TReturn1>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n): PushIterable<Out<TReturn2>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n): PushIterable<Out<TReturn3>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<\n T, TReturn1,\n TArgs2 extends Args<TReturn1>, TReturn2,\n TArgs3 extends Args<TReturn2>, TReturn3,\n TArgs4 extends Args<TReturn3>, TReturn4,\n TArgs5 extends Args<TReturn4>, TReturn5,\n TArgs6 extends Args<TReturn5>, TReturn6,\n TArgs7 extends Args<TReturn6>, TReturn7,\n TArgs8 extends Args<TReturn7>, TReturn8,\n TArgs9 extends Args<TReturn8>, TReturn9,\n TArgs10 extends Args<TReturn9>, TReturn10,\n TArgs11 extends Args<TReturn10>, TReturn11,\n TArgs12 extends Args<TReturn11>, TReturn12,\n TArgs13 extends Args<TReturn12>, TReturn13,\n >(\n it: Iterable<T>,\n pass1: (this: void, arg: T) => TReturn1,\n pass2: (this: void, ...args: TArgs2) => TReturn2,\n pass3: (this: void, ...args: TArgs3) => TReturn3,\n pass4: (this: void, ...args: TArgs4) => TReturn4,\n pass5: (this: void, ...args: TArgs5) => TReturn5,\n pass6: (this: void, ...args: TArgs6) => TReturn6,\n pass7: (this: void, ...args: TArgs7) => TReturn7,\n pass8: (this: void, ...args: TArgs8) => TReturn8,\n pass9: (this: void, ...args: TArgs9) => TReturn9,\n pass10: (this: void, ...args: TArgs10) => TReturn10,\n pass11: (this: void, ...args: TArgs11) => TReturn11,\n pass12: (this: void, ...args: TArgs12) => TReturn12,\n pass13: (this: void, ...args: TArgs13) => TReturn13,\n): PushIterable<Out<TReturn4>>;\n\nexport function thruIt<T, TReturn>(\n it: Iterable<T>,\n ...passes: ((...args: any[]) => any)[]\n): PushIterable<TReturn> {\n\n const chain = (outcome: PushIterable<any>[], index: number): IterableCallChain => {\n\n const lastPass = index >= passes.length;\n\n ++index;\n\n const pass = index < passes.length ? passes[index] : () => { /* empty pass */ };\n const handleResult = (outcome: PushIterable<any>[], callResult: any, arg: any): void => {\n if (isNextCall(callResult)) {\n callResult[NextCall__symbol](chain(outcome, index), pass);\n } else if (lastPass) {\n outcome.push(overOne(arg));\n } else {\n chain(outcome, index).pass(pass, callResult);\n }\n };\n\n return ({\n call<A extends any[]>(fn: (...args: A) => any, args: A): void {\n handleResult(outcome, fn(...args), args);\n },\n pass<A>(fn: (arg: A) => any, arg: A): void {\n handleResult(outcome, fn(arg), arg);\n },\n skip() {/* skip item */},\n iterate<I>(fn: (this: void, arg: I) => void, iterable: Iterable<I>): void {\n outcome.push(flatMapIt(\n iterable,\n item => {\n\n const itemOutcome: PushIterable<any>[] = [];\n\n handleResult(itemOutcome, fn(item), item);\n\n return flatMapArray(itemOutcome);\n },\n ));\n },\n });\n };\n\n const finalOutcome: PushIterable<any>[] = [];\n\n chain(finalOutcome, 0).iterate(passes[0], it);\n\n return flatMapArray<TReturn>(finalOutcome);\n}\n"],"names":[],"mappings":";;;AAAA;;;;AAOA;;;;;;;;;;;;SAYgB,WAAW,CAAI,QAAqB;IAClD,OAAO,QAAQ,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClE;;ACrBA;;;;SA2QgB,MAAM,CAClB,EAAe,EACf,GAAG,MAAmC;IAGxC,MAAM,KAAK,GAAG,CAAC,OAA4B,EAAE,KAAa;QAExD,MAAM,QAAQ,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC;QAExC,EAAE,KAAK,CAAC;QAER,MAAM,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,SAA0B,CAAC;QAChF,MAAM,YAAY,GAAG,CAAC,OAA4B,EAAE,UAAe,EAAE,GAAQ;YAC3E,IAAI,UAAU,CAAC,UAAU,CAAC,EAAE;gBAC1B,UAAU,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;aAC3D;iBAAM,IAAI,QAAQ,EAAE;gBACnB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aAC5B;iBAAM;gBACL,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;aAC9C;SACF,CAAC;QAEF,QAAQ;YACN,IAAI,CAAkB,EAAuB,EAAE,IAAO;gBACpD,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;aAC1C;YACD,IAAI,CAAI,EAAmB,EAAE,GAAM;gBACjC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;aACrC;YACD,IAAI,MAAoB;YACxB,OAAO,CAAI,EAAgC,EAAE,QAAqB;gBAChE,OAAO,CAAC,IAAI,CAAC,SAAS,CAClB,QAAQ,EACR,IAAI;oBAEF,MAAM,WAAW,GAAwB,EAAE,CAAC;oBAE5C,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;oBAE1C,OAAO,YAAY,CAAC,WAAW,CAAC,CAAC;iBAClC,CACJ,CAAC,CAAC;aACJ;SACF,EAAE;KACJ,CAAC;IAEF,MAAM,YAAY,GAAwB,EAAE,CAAC;IAE7C,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE9C,OAAO,YAAY,CAAU,YAAY,CAAC,CAAC;AAC7C;;;;"} |
| /** | ||
| * A key of {@link PushIterable} iteration method. | ||
| */ | ||
| const PushIterator__symbol = ( /*#__PURE__*/Symbol('push-iterator')); | ||
| function isPushIterable(iterable) { | ||
| return !!iterable[PushIterator__symbol]; | ||
| } | ||
| function iteratorOf(iterable) { | ||
| return iterable[Symbol.iterator](); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a push iterable implementation. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterate A function iterating over iterable elements conforming to {@link PushIterable.Iterate} requirements. | ||
| * | ||
| * @returns New push iterable instance performing iteration by `forNext` function. | ||
| */ | ||
| function makePushIterable(iterate) { | ||
| return { | ||
| [Symbol.iterator]: PushIterable$iterator, | ||
| [PushIterator__symbol]: iterate, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterable$iterator() { | ||
| return this[PushIterator__symbol](); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given push iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * Calling this function is the same as calling `!iterable[PushIterator__symbol](accept).isOver()`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable A push iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns `true` if there are more elements to iterate, or `false` otherwise. The former is possible only when | ||
| * iteration suspended, i.e. `accept` returned `true`. | ||
| */ | ||
| function pushIterated(iterable, accept) { | ||
| return !iterable[PushIterator__symbol](accept).isOver(); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a push iterator implementation. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param forNext A function iterating over elements conforming to push iteration protocol. | ||
| * | ||
| * @returns New push iterator instance performing iteration by `forNext` function. | ||
| */ | ||
| function makePushIterator(forNext) { | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| } | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: PushIterator$next, | ||
| isOver: () => over, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$iterator() { | ||
| return this; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$next() { | ||
| for (;;) { | ||
| let result; | ||
| const over = !pushIterated(this, value => { | ||
| result = { value }; | ||
| return true; | ||
| }); | ||
| if (result) { | ||
| return result; | ||
| } | ||
| if (over) { | ||
| return { done: true }; | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$noNext() { | ||
| return { done: true }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function PushIterator$dontIterate(_accept) { | ||
| /* do not iterate */ | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| const emptyPushIterator = { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](_accept) { | ||
| return this; | ||
| }, | ||
| next: () => ({ done: true }), | ||
| isOver: () => true, | ||
| }; | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over the head elements of the given push iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * Calling this function is the same as calling `iterable[PushIterator__symbol](accept)`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable A push iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns A push iterator instance representing the tail of the given iterable. This iterator can be used to continue | ||
| * iteration with, unless `accept` returned `false`. In the latter case the further iteration won't be possible. | ||
| */ | ||
| function pushHead(iterable, accept) { | ||
| return iterable[PushIterator__symbol](accept); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function indexedItemOf(indexed, index) { | ||
| return indexed.item(index); // The index is always valid. | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverIndexed(indexed, elementOf) { | ||
| return accept => { | ||
| let i = 0; | ||
| const forNext = (accept) => { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| for (;;) { | ||
| const goOn = accept(elementOf(indexed, i++)); | ||
| if (i >= indexed.length || goOn === false) { | ||
| return false; | ||
| } | ||
| if (goOn === true) { | ||
| return true; | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return emptyPushIterator; | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| if (i < indexed.length) { | ||
| return { value: elementOf(indexed, i++) }; | ||
| } | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function arrayElementOf(array, index) { | ||
| return array[index]; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverArray(array) { | ||
| return iterateOverIndexed(array, arrayElementOf); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of array-like structure. | ||
| * | ||
| * @typeParam T Array elements type. | ||
| * @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc. | ||
| * | ||
| * @returns New push iterable over array elements. | ||
| */ | ||
| function overArray(array) { | ||
| return makePushIterable(iterateOverArray(array)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * In contrast to {@link pushIterated} function, this one accepts any iterable instance. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns `true` if there are more elements to iterate, or `false` otherwise. The former is possible only when | ||
| * iteration suspended, i.e. `accept` returned `true`. | ||
| */ | ||
| function itsIterated(iterable, accept) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushIterated(iterable, accept); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| if (isPushIterable(it)) { | ||
| return pushIterated(it, accept); | ||
| } | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const status = accept(next.value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Performs the given `action` for each element of the given `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable of elements to perform actions on. | ||
| * @param action An action to perform on each iterable element. This is a function accepting an element as its only | ||
| * parameter. | ||
| */ | ||
| function itsEach(iterable, action) { | ||
| itsIterated(iterable, element => { action(element); }); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * @internal | ||
| */ | ||
| const itsElements$defaultConverter = (element) => element; | ||
| function itsElements(source, convert = itsElements$defaultConverter) { | ||
| if (isPushIterable(source)) { | ||
| return pushedElements(source, convert); | ||
| } | ||
| const it = iteratorOf(source); | ||
| return isPushIterable(it) ? pushedElements(it, convert) : Array.from(source, convert); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedElements(it, convert) { | ||
| const result = []; | ||
| pushIterated(it, element => { result.push(convert(element)); }); | ||
| return result; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Checks whether the given `iterable` is empty. | ||
| * | ||
| * @param iterable An iterable or push iterable to check for elements. | ||
| * | ||
| * @return `true` if the given iterable contains at least one element, or `false` otherwise. | ||
| */ | ||
| function itsEmpty(iterable) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushedEmpty(iterable); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? pushedEmpty(it) : !!it.next().done; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedEmpty(it) { | ||
| let isEmpty = true; | ||
| pushIterated(it, _element /* Unused parameter to prevent deoptimization */ => isEmpty = false); | ||
| return isEmpty; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Tests whether all elements of the given `iterable` pass the test implemented by the provided function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to test elements of. | ||
| * @param test A predicate function to test each element. Returns `true` to continue tests, or `false` to stop it | ||
| * and return `false` from the method call. It accepts the tested element as the only parameter. | ||
| * | ||
| * @returns `true` if the `test` function returned a truthy value for every element, or `false` otherwise. | ||
| * Returns `true` for empty iterable. | ||
| */ | ||
| function itsEvery(iterable, test) { | ||
| let allMatch = true; | ||
| itsIterated(iterable, element => { | ||
| allMatch = !!test(element); | ||
| if (!allMatch) { | ||
| return false; | ||
| } | ||
| return; | ||
| }); | ||
| return allMatch; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Searches for the value in `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @typeParam TFound Found value type. | ||
| * @param iterable An iterable to extract element from. | ||
| * @param search A function extracting the value from elements. It is called for each iterated element until the value | ||
| * found. Accepts element as the only parameter, and returns extracted value. If returns `false` or `undefined` the | ||
| * search continues from the next element. | ||
| * | ||
| * @return Either found value or `undefined`. | ||
| */ | ||
| function itsFind(iterable, search) { | ||
| let find; | ||
| itsIterated(iterable, element => { | ||
| const result = search(element); | ||
| if (result !== false && result !== undefined) { | ||
| find = result; | ||
| return true; | ||
| } | ||
| return; | ||
| }); | ||
| return find; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Extracts the first element of the given `iterable`, if any. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to extract element from. | ||
| * | ||
| * @return Either the first element, or `undefined` if the given `iterable` is empty. | ||
| */ | ||
| function itsFirst(iterable) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushedFirst(iterable); | ||
| } | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? pushedFirst(it) : rawFirst(it); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function pushedFirst(it) { | ||
| let first; | ||
| pushIterated(it, element => { | ||
| first = element; | ||
| return false; | ||
| }); | ||
| return first; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawFirst(it) { | ||
| const result = it.next(); | ||
| return result.done ? undefined : result.value; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function toPushIterator(it, forNext) { | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if ((over = !!accept && !forNext(accept))) { | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| const res = it.next(); | ||
| if (res.done) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| } | ||
| return res; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next() { | ||
| return next(); | ||
| }, | ||
| isOver: () => over, | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawIteratorPusher(it) { | ||
| return accept => { | ||
| for (;;) { | ||
| const res = it.next(); | ||
| if (res.done) { | ||
| return false; | ||
| } | ||
| const status = accept(res.value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Iterates over elements of the given iterable. | ||
| * | ||
| * Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either | ||
| * `true` or `false`. | ||
| * | ||
| * In contrast to {@link pushHead} function, this one accepts any iterable instance. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate elements of. | ||
| * @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return | ||
| * `true` to suspend iteration, or `false` to stop it. | ||
| * | ||
| * @returns A push iterator instance representing the tail of the given iterable. This iterator can be used to continue | ||
| * iteration with, unless `accept` returned `false`. In the latter case the further iteration won't be possible. | ||
| */ | ||
| function itsHead(iterable, accept) { | ||
| if (isPushIterable(iterable)) { | ||
| return pushHead(iterable, accept); | ||
| } | ||
| if (Array.isArray(iterable)) { | ||
| return arrayHead(iterable, accept); | ||
| } | ||
| return rawIterableHead(iterable, accept); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function arrayHead(array, accept) { | ||
| return array.length ? iterateOverArray(array)(accept) : emptyPushIterator; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function rawIterableHead(iterable, accept) { | ||
| const it = iteratorOf(iterable); | ||
| if (isPushIterable(it)) { | ||
| return pushHead(it, accept); | ||
| } | ||
| const forEach = rawIteratorPusher(it); | ||
| return forEach(accept) ? toPushIterator(it, forEach) : emptyPushIterator; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Starts iteration over the given `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable or push iterable to iterate over. | ||
| * | ||
| * @return A push iterator iterating over the given iterable. | ||
| */ | ||
| function itsIterator(iterable) { | ||
| const it = iteratorOf(iterable); | ||
| return isPushIterable(it) ? it : toPushIterator(it, rawIteratorPusher(it)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Extracts the first element matching the given condition from `iterable`. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to extract element from. | ||
| * @param test A predicate function to test elements. Returns truthy value for matching one. It accepts the tested | ||
| * element as the only parameter. | ||
| * | ||
| * @return Either the matching element, or `undefined` if no elements match. | ||
| */ | ||
| function itsMatch(iterable, test) { | ||
| let match; | ||
| itsIterated(iterable, element => { | ||
| if (test(element)) { | ||
| match = element; | ||
| return true; | ||
| } | ||
| return; | ||
| }); | ||
| return match; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Applies a function against an accumulator and each element of the given `iterable` to reduce elements to a single | ||
| * value. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @typeParam TResult A type of reduced value. | ||
| * @param iterable An iterable to reduce values of. | ||
| * @param reducer A function to apply the value returned from the previous `reducer` call and to each element. | ||
| * @param initialValue Initial value passed to the first `reducer` call. | ||
| * | ||
| * @return Reduced value returned from the last `reducer` call, or `initialValue` if there is no elements in the given | ||
| * `iterable`. | ||
| */ | ||
| function itsReduction(iterable, reducer, initialValue) { | ||
| let reduced = initialValue; | ||
| itsIterated(iterable, element => { reduced = reducer(reduced, element); }); | ||
| return reduced; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Tests whether at least one element of the given `iterable` passes the test implemented by the provided function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to test elements of. | ||
| * @param test A predicate function to test each element. Returns `false` to continue tests, or `true` to stop it | ||
| * and return `true` from the method call. It accepts the tested element as the only parameter. | ||
| * | ||
| * @returns `true` if the callback function returned a truthy value for at least one element in the array, or `false` | ||
| * otherwise. Returns `false` for empty iterable. | ||
| */ | ||
| function itsSome(iterable, test) { | ||
| let someMatches = false; | ||
| itsIterated(iterable, element => { | ||
| someMatches = !!test(element); | ||
| if (someMatches) { | ||
| return false; | ||
| } | ||
| return; | ||
| }); | ||
| return someMatches; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Returns a {@link PushIterator push iterable iterator} without elements. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * | ||
| * @returns Empty push iterable and push iterator instance. | ||
| */ | ||
| function overNone() { | ||
| return emptyPushIterator; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of iterator created by the given function. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterate A function creating new iterator. | ||
| * | ||
| * @returns New push iterable over elements of created iterator. | ||
| */ | ||
| function overIterator(iterate) { | ||
| return makePushIterable(iterateOverRawIterator(iterate)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverRawIterator(iterate) { | ||
| return accept => { | ||
| const it = iterate(); | ||
| if (isPushIterable(it)) { | ||
| return it[PushIterator__symbol](accept); | ||
| } | ||
| const forNext = rawIteratorPusher(it); | ||
| return accept && !forNext(accept) ? overNone() : toPushIterator(it, forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of the given raw iterable. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param iterable An iterable to iterate over elements of. | ||
| * | ||
| * @returns New push iterable over elements of the given `iterable`. | ||
| */ | ||
| function overIterable(iterable) { | ||
| return Array.isArray(iterable) | ||
| ? overArray(iterable) | ||
| : overIterator(() => iteratorOf(iterable)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of other iterables. | ||
| * | ||
| * @typeParam T Iterated elements type. | ||
| * @param sources Source iterables to iterate over elements of. | ||
| * | ||
| * @returns New push iterable over elements of the given `sources`. | ||
| */ | ||
| function overElementsOf(...sources) { | ||
| return sources.length > 1 | ||
| ? makePushIterable(iterateOverSubElements(sources)) | ||
| : (sources.length | ||
| ? overIterable(sources[0]) | ||
| : overNone()); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverSubElements(sources) { | ||
| return accept => { | ||
| let i = 0; | ||
| let src = sources[0]; | ||
| const forNext = (accept) => { | ||
| for (;;) { | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const srcTail = itsHead(src, element => status = accept(element)); | ||
| if (srcTail.isOver()) { | ||
| if (++i >= sources.length) { | ||
| return false; | ||
| } | ||
| src = sources[i]; | ||
| } | ||
| else { | ||
| src = srcTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over items of {@link IndexedItemList indexed list}. | ||
| * | ||
| * @typeParam T Indexed items type. | ||
| * @param indexed An indexed list of items. E.g. DOM `NodeList`. | ||
| * | ||
| * @returns New push iterable over list items. | ||
| */ | ||
| function overIndexed(indexed) { | ||
| return makePushIterable(iterateOverIndexed(indexed, indexedItemOf)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over one value. | ||
| * | ||
| * @typeParam T Iterated element value type. | ||
| * @param value A value to iterate over. | ||
| * | ||
| * @returns New push iterable over the given value. | ||
| */ | ||
| function overOne(value) { | ||
| return makePushIterable(iterateOverOneValue(value)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverOneValue(value) { | ||
| return accept => { | ||
| if (accept) { | ||
| accept(value); | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| if (over) { | ||
| return overNone(); | ||
| } | ||
| if (accept) { | ||
| over = true; | ||
| accept(value); | ||
| return overNone(); | ||
| } | ||
| return this; | ||
| }, | ||
| next() { | ||
| if (over) { | ||
| return { done: over }; | ||
| } | ||
| over = true; | ||
| return { value }; | ||
| }, | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over many values. | ||
| * | ||
| * @typeParam T Iterated elements value type. | ||
| * @param values Values to iterate over. | ||
| * | ||
| * @returns New push iterable over the given values. | ||
| */ | ||
| function overMany(...values) { | ||
| return values.length > 1 | ||
| ? overArray(values) | ||
| : (values.length | ||
| ? overOne(values[0]) | ||
| : overNone()); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over elements of array-like structure in reverse order. | ||
| * | ||
| * @typeParam T Array elements type. | ||
| * @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc. | ||
| * | ||
| * @returns New push iterable over array elements in reverse order. | ||
| */ | ||
| function reverseArray(array) { | ||
| return makePushIterable(iterateOverArrayReversely(array)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverArrayReversely(array) { | ||
| return accept => { | ||
| let i = array.length - 1; | ||
| const forNext = (accept) => { | ||
| if (i < 0) { | ||
| return false; | ||
| } | ||
| for (;;) { | ||
| const status = accept(array[i--]); | ||
| if (i < 0) { | ||
| return false; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return true; | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| if (i < 0) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| } | ||
| return { value: array[i--] }; | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over keys of the given object. | ||
| * | ||
| * A list of keys is constructed using `Reflect.ownKeys()`. | ||
| * | ||
| * @typeParam TObj Source object type. | ||
| * @param source An object to select keys from. | ||
| * | ||
| * @returns New push iterable over own object keys retrieved by `Reflect.ownKeys()`. | ||
| */ | ||
| function overKeys(source) { | ||
| return overArray(Reflect.ownKeys(source)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverFilteredIndexed(indexed, elementOf, test) { | ||
| return accept => { | ||
| let i = 0; | ||
| const forNext = (accept) => { | ||
| for (;;) { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| const value = elementOf(indexed, i++); | ||
| if (test(value)) { | ||
| const status = accept(value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| if (accept && !forNext(accept)) { | ||
| return overNone(); | ||
| } | ||
| let over = false; | ||
| let iterate = (accept) => { | ||
| if (accept && !forNext(accept)) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
| next = PushIterator$noNext; | ||
| } | ||
| }; | ||
| let next = () => { | ||
| for (;;) { | ||
| if (i >= indexed.length) { | ||
| over = true; | ||
| iterate = PushIterator$dontIterate; | ||
| next = PushIterator$noNext; | ||
| return { done: true }; | ||
| } | ||
| const value = elementOf(indexed, i++); | ||
| if (test(value)) { | ||
| return { value }; | ||
| } | ||
| } | ||
| }; | ||
| return { | ||
| [Symbol.iterator]: PushIterator$iterator, | ||
| [PushIterator__symbol](accept) { | ||
| iterate(accept); | ||
| return this; | ||
| }, | ||
| next: () => next(), | ||
| isOver: () => over, | ||
| }; | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterArray(array, test) { | ||
| return makePushIterable(iterateOverFilteredIndexed(array, arrayElementOf, test)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterIndexed(array, test) { | ||
| return makePushIterable(iterateOverFilteredIndexed(array, indexedItemOf, test)); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function filterIt(source, test) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? filterPusher(source, test) : filterRawPusher(source, test); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function filterPusher(source, test) { | ||
| return accept => { | ||
| const tail = pushHead(source, element => { | ||
| if (test(element)) { | ||
| return accept(element); | ||
| } | ||
| return; | ||
| }); | ||
| source = tail; | ||
| return !tail.isOver(); | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function filterRawPusher(source, test) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return filterPusher(it, test); | ||
| } | ||
| return accept => { | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const value = next.value; | ||
| if (test(value)) { | ||
| const status = accept(value); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function iterateOverFlattenedIndexed(indexed, elementsOf) { | ||
| return accept => { | ||
| let i = 0; | ||
| let subs; | ||
| const forNext = (accept) => { | ||
| if (i >= indexed.length) { | ||
| return false; | ||
| } | ||
| if (!subs) { | ||
| subs = elementsOf(indexed, i); | ||
| } | ||
| for (;;) { | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| if (subsTail.isOver()) { | ||
| if (++i >= indexed.length) { | ||
| return false; | ||
| } | ||
| subs = elementsOf(indexed, i); | ||
| } | ||
| else { | ||
| subs = subsTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapArray(array, convert) { | ||
| return makePushIterable(iterateOverFlattenedIndexed(array, convert | ||
| ? (array, index) => convert(array[index]) | ||
| : flatMapArray$defaultElementOf)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapArray$defaultElementOf(array, index) { | ||
| return array[index]; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapIndexed(indexed, convert) { | ||
| return makePushIterable(iterateOverFlattenedIndexed(indexed, convert | ||
| ? (indexed, index) => convert(indexed.item(index)) | ||
| : flatMapIndexed$defaultElementOf)); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapIndexed$defaultElementOf(indexed, index) { | ||
| return indexed.item(index); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| function flatMapIt(source, convert = flatMapIt$defaultConverter) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? flatMapPusher(source, convert) : flatMapRawPusher(source, convert); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapPusher(source, convert) { | ||
| let subs; | ||
| let lastSrc = false; | ||
| return accept => { | ||
| for (;;) { | ||
| while (!subs) { | ||
| const sourceTail = pushHead(source, src => { | ||
| subs = convert(src); | ||
| return true; | ||
| }); | ||
| source = sourceTail; | ||
| if (sourceTail.isOver()) { | ||
| if (!subs) { | ||
| return false; | ||
| } | ||
| lastSrc = true; | ||
| } | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| if (subsTail.isOver()) { | ||
| subs = undefined; | ||
| if (lastSrc) { | ||
| return false; | ||
| } | ||
| } | ||
| else { | ||
| subs = subsTail; | ||
| } | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapRawPusher(source, convert) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return flatMapPusher(it, convert); | ||
| } | ||
| let subs; | ||
| return accept => { | ||
| for (;;) { | ||
| if (!subs) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| subs = convert(next.value); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-invalid-void-type | ||
| let status; | ||
| const subsTail = itsHead(subs, element => status = accept(element)); | ||
| subs = subsTail.isOver() ? undefined : subsTail; | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function flatMapIt$defaultConverter(element) { | ||
| return element; | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every element of the | ||
| * given `array`. | ||
| * | ||
| * @typeParam TSrc A type of array elements. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param array A source array-like instance. | ||
| * @param convert A function that produces an element of new iterable, taking array element as the only parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapArray(array, convert) { | ||
| return makePushIterable(iterateOverIndexed(array, (array, index) => convert(array[index]))); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every item of the | ||
| * given indexed list. | ||
| * | ||
| * @typeParam TSrc A type of indexed list items. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param indexed A source indexed items list. | ||
| * @param convert A function that produces an element of new iterable, taking list item as the only parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapIndexed(indexed, convert) { | ||
| return makePushIterable(iterateOverIndexed(indexed, (list, index) => convert(list.item(index) /* The index is always valid */))); | ||
| } | ||
| /** | ||
| * @packageDocumentation | ||
| * @module @proc7ts/push-iterator | ||
| */ | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} with the results of calling a provided function on every element of the | ||
| * `source` iterable. | ||
| * | ||
| * @typeParam TSrc A type of source elements. | ||
| * @typeParam TConv A type of converted elements. | ||
| * @param source A source iterable. | ||
| * @param convert A function that produces an element of the new iterable, taking the source element as the only | ||
| * parameter. | ||
| * | ||
| * @returns New push iterable of transformed elements. | ||
| */ | ||
| function mapIt(source, convert) { | ||
| return makePushIterable(accept => { | ||
| const forNext = isPushIterable(source) ? mapPusher(source, convert) : mapRawPusher(source, convert); | ||
| return accept && !forNext(accept) ? overNone() : makePushIterator(forNext); | ||
| }); | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function mapPusher(source, convert) { | ||
| return accept => { | ||
| const tail = pushHead(source, element => accept(convert(element))); | ||
| source = tail; | ||
| return !tail.isOver(); | ||
| }; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| function mapRawPusher(source, convert) { | ||
| const it = iteratorOf(source); | ||
| if (isPushIterable(it)) { | ||
| return mapPusher(it, convert); | ||
| } | ||
| return accept => { | ||
| for (;;) { | ||
| const next = it.next(); | ||
| if (next.done) { | ||
| return false; | ||
| } | ||
| const status = accept(convert(next.value)); | ||
| if (typeof status === 'boolean') { | ||
| return status; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| /** | ||
| * Creates a {@link PushIterable push iterable} over the property key/value entries of the given object. | ||
| * | ||
| * A list of keys is constructed using `Reflect.ownKeys()`. | ||
| * | ||
| * @typeParam TObj Object type. | ||
| * | ||
| * @param source An object to select keys and values from. | ||
| * | ||
| * @returns New push iterable of object property entries. | ||
| */ | ||
| function overEntries(source) { | ||
| return mapIt(overKeys(source), key => [key, source[key]]); | ||
| } | ||
| export { PushIterator__symbol, filterArray, filterIndexed, filterIt, flatMapArray, flatMapIndexed, flatMapIt, isPushIterable, iteratorOf, itsEach, itsElements, itsEmpty, itsEvery, itsFind, itsFirst, itsHead, itsIterated, itsIterator, itsMatch, itsReduction, itsSome, makePushIterable, makePushIterator, mapArray, mapIndexed, mapIt, overArray, overElementsOf, overEntries, overIndexed, overIterable, overIterator, overKeys, overMany, overNone, overOne, pushHead, pushIterated, reverseArray }; | ||
| //# sourceMappingURL=push-iterator.mjs.map |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Yes
NaN380616
-35.46%116
-1.69%Updated