You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@proc7ts/push-iterator

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@proc7ts/push-iterator - npm Package Compare versions

Comparing version
1.1.0
to
2.0.0
+27
d.ts/base/is-push-iterable.d.ts
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
import type { PushIterable } from '../push-iterable';
import type { PushIterator } from '../push-iterator';
/**
* Checks whether the given iterable conforms to {@link PushIterable push iteration protocol}.
*
* @typeParam T Iterated elements type.
* @param iterable An iterable to check.
*
* @returns `true` if the given `iterable` has a {@link PushIterator__symbol [PushIterator__symbol]} property,
* or `false` otherwise.
*/
export declare function isPushIterable<T>(iterable: Iterable<T>): iterable is PushIterable<T>;
/**
* Checks whether the given iterator conforms to {@link PushIterable push iteration protocol}.
*
* @typeParam T Iterated elements type.
* @param iterator An iterator to check.
*
* @returns `true` if the given `iterator` has a {@link PushIterator__symbol [PushIterator__symbol]} property,
* or `false` otherwise.
*/
export declare function isPushIterable<T>(iterator: Iterator<T>): iterator is PushIterator<T>;
//# sourceMappingURL=is-push-iterable.d.ts.map
{"version":3,"file":"is-push-iterable.d.ts","sourceRoot":"","sources":["../../src/base/is-push-iterable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;AAEtF;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC"}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
import { PushIterable } from '../push-iterable';
/**
* 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.
*/
export declare function makePushIterable<T>(iterate: PushIterable.Iterate<T>): PushIterable<T>;
//# sourceMappingURL=make-push-iterable.d.ts.map
{"version":3,"file":"make-push-iterable.d.ts","sourceRoot":"","sources":["../../src/base/make-push-iterable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AAGtE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAKrF"}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
import { PushIterable } from '../push-iterable';
import type { PushIterator } from '../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.
*/
export declare function pushHead<T>(iterable: PushIterable<T>, accept: PushIterator.Acceptor<T>): PushIterator<T>;
//# sourceMappingURL=push-head.d.ts.map
{"version":3,"file":"push-head.d.ts","sourceRoot":"","sources":["../../src/base/push-head.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAExG"}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
import { PushIterable } from '../push-iterable';
import type { PushIterator } from '../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`.
*/
export declare function pushIterated<T>(iterable: PushIterable<T>, accept: PushIterator.Acceptor<T>): boolean;
//# sourceMappingURL=push-iterated.d.ts.map
{"version":3,"file":"push-iterated.d.ts","sourceRoot":"","sources":["../../src/base/push-iterated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAwB,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAEpG"}
/**
* Searches for the value in `iterable`.
*
* @typeParam T Iterated elements type.
* @typeParam R 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`.
*/
export declare function itsFind<T, R>(iterable: Iterable<T>, search: (this: void, element: T) => R | false | undefined): R | undefined;
//# sourceMappingURL=its-find.d.ts.map
{"version":3,"file":"its-find.d.ts","sourceRoot":"","sources":["../../src/consumption/its-find.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,SAAS,GAC1D,CAAC,GAAG,SAAS,CAoBf"}
import type { PushIterator } from '../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.
*/
export declare function itsHead<T>(iterable: Iterable<T>, accept: PushIterator.Acceptor<T>): PushIterator<T>;
//# sourceMappingURL=its-head.d.ts.map
{"version":3,"file":"its-head.d.ts","sourceRoot":"","sources":["../../src/consumption/its-head.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAQnG"}
import type { PushIterator } from '../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`.
*/
export declare function itsIterated<T>(iterable: Iterable<T>, accept: PushIterator.Acceptor<T>): boolean;
//# sourceMappingURL=its-iterated.d.ts.map
{"version":3,"file":"its-iterated.d.ts","sourceRoot":"","sources":["../../src/consumption/its-iterated.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAyB/F"}
import type { PushIterator } from '../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.
*/
export declare function itsIterator<T>(iterable: Iterable<T>): PushIterator<T>;
//# sourceMappingURL=its-iterator.d.ts.map
{"version":3,"file":"its-iterator.d.ts","sourceRoot":"","sources":["../../src/consumption/its-iterator.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAKrE"}
/**
* 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.
*/
export declare function itsMatch<T>(iterable: Iterable<T>, test: (this: void, element: T) => boolean): T | undefined;
//# sourceMappingURL=its-match.d.ts.map
{"version":3,"file":"its-match.d.ts","sourceRoot":"","sources":["../../src/consumption/its-match.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAAG,CAAC,GAAG,SAAS,CAgB3G"}
+5
-2

@@ -0,4 +1,7 @@

export * from './is-push-iterable';
export * from './iterator-of';
export * from './its-iterator';
export * from './make-push-iterator';
export { makePushIterable } from './make-push-iterable';
export { makePushIterator } from './make-push-iterator';
export * from './push-head';
export * from './push-iterated';
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}

@@ -5,13 +5,39 @@ /**

*/
import type { PushOrRawIterator } from '../push-iterator';
import type { PushIterable } from '../push-iterable';
import type { PushIterator } from '../push-iterator';
/**
* Constructs iterator over elements of the given `iterable`.
* Creates a push iterator over elements of the given push `iterable`.
*
* Calls `iterable[Symbol.iterator]()` and returns its result.
*
* @typeParam T Iterated elements type.
* @param iterable A push iterable to construct iterator of.
*
* @returns Push iterator.
*/
export declare function iteratorOf<T>(iterable: PushIterable<T>): PushIterator<T>;
/**
* Creates an iterable iterator over elements of the given `iterable` supporting iterable iteration.
*
* Calls `iterable[Symbol.iterator]()` and returns its result.
*
* @typeParam T Iterated elements type.
* @param iterable A push iterable to construct iterator of.
*
* @returns Iterable iterator.
*/
export declare function iteratorOf<T>(iterable: {
[Symbol.iterator](): IterableIterator<T>;
}): IterableIterator<T>;
/**
* Creates iterator over elements of the given `iterable`.
*
* Calls `iterable[Symbol.iterator]()` and returns its result.
*
* @typeParam T Iterated elements type.
* @param iterable An iterable to construct iterator of.
*
* @returns Either push or raw iterable.
* @returns Either push or raw iterator.
*/
export declare function iteratorOf<T>(iterable: Iterable<T>): PushOrRawIterator<T>;
export declare function iteratorOf<T>(iterable: Iterable<T>): Iterator<T>;
//# sourceMappingURL=iterator-of.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"iterator-of.d.ts","sourceRoot":"","sources":["../../src/base/iterator-of.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAEzE"}
{"version":3,"file":"iterator-of.d.ts","sourceRoot":"","sources":["../../src/base/iterator-of.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE;IAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAE3G;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC"}
import type { PushIterator } from '../push-iterator';
/**
* Creates push iterator implementation.
* Creates a push iterator implementation.
*
* @param forNext A function iterating over elements conforming to {@link PushIterator.forNext} requirement.
* @typeParam T Iterated elements type.
* @param forNext A function iterating over elements conforming to push iteration protocol.
*

@@ -7,0 +8,0 @@ * @returns New push iterator instance performing iteration by `forNext` function.

@@ -1,1 +0,1 @@

{"version":3,"file":"make-push-iterator.d.ts","sourceRoot":"","sources":["../../src/base/make-push-iterator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAMpF"}
{"version":3,"file":"make-push-iterator.d.ts","sourceRoot":"","sources":["../../src/base/make-push-iterator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAmBpF"}

@@ -1,1 +0,1 @@

{"version":3,"file":"over-array.d.ts","sourceRoot":"","sources":["../../src/construction/over-array.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAMjE"}
{"version":3,"file":"over-array.d.ts","sourceRoot":"","sources":["../../src/construction/over-array.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEjE"}

@@ -1,1 +0,1 @@

{"version":3,"file":"over-elements-of.d.ts","sourceRoot":"","sources":["../../src/construction/over-elements-of.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAMrF"}
{"version":3,"file":"over-elements-of.d.ts","sourceRoot":"","sources":["../../src/construction/over-elements-of.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAMrF"}

@@ -6,7 +6,7 @@ import type { PushIterable } from '../push-iterable';

* @typeParam T Iterated elements type.
* @param source Source iterable to iterate over elements of.
* @param iterable An iterable to iterate over elements of.
*
* @returns New push iterable over elements of the given `source`.
* @returns New push iterable over elements of the given `iterable`.
*/
export declare function overIterable<T>(source: Iterable<T>): PushIterable<T>;
export declare function overIterable<T>(iterable: Iterable<T>): PushIterable<T>;
//# sourceMappingURL=over-iterable.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"over-iterable.d.ts","sourceRoot":"","sources":["../../src/construction/over-iterable.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAIpE"}
{"version":3,"file":"over-iterable.d.ts","sourceRoot":"","sources":["../../src/construction/over-iterable.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAItE"}

@@ -1,1 +0,1 @@

{"version":3,"file":"over-one.d.ts","sourceRoot":"","sources":["../../src/construction/over-one.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpD"}
{"version":3,"file":"over-one.d.ts","sourceRoot":"","sources":["../../src/construction/over-one.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpD"}

@@ -1,1 +0,1 @@

{"version":3,"file":"reverse-array.d.ts","sourceRoot":"","sources":["../../src/construction/reverse-array.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpE"}
{"version":3,"file":"reverse-array.d.ts","sourceRoot":"","sources":["../../src/construction/reverse-array.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAEpE"}

@@ -5,5 +5,10 @@ export * from './its-each';

export * from './its-every';
export * from './its-find';
export * from './its-first';
export * from './its-head';
export * from './its-iterated';
export * from './its-iterator';
export * from './its-match';
export * from './its-reduction';
export * from './its-some';
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumption/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consumption/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"its-each.d.ts","sourceRoot":"","sources":["../../src/consumption/its-each.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAMhG"}
{"version":3,"file":"its-each.d.ts","sourceRoot":"","sources":["../../src/consumption/its-each.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAEhG"}

@@ -8,3 +8,3 @@ /**

*/
export declare function itsEmpty(iterable: Iterable<any>): boolean;
export declare function itsEmpty(iterable: Iterable<unknown>): boolean;
//# sourceMappingURL=its-empty.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"its-empty.d.ts","sourceRoot":"","sources":["../../src/consumption/its-empty.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,OAAO,CAMzD"}
{"version":3,"file":"its-empty.d.ts","sourceRoot":"","sources":["../../src/consumption/its-empty.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,CAQ7D"}

@@ -1,1 +0,1 @@

{"version":3,"file":"its-every.d.ts","sourceRoot":"","sources":["../../src/consumption/its-every.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,OAAO,CAMT"}
{"version":3,"file":"its-every.d.ts","sourceRoot":"","sources":["../../src/consumption/its-every.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACtB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,OAAO,CAgBT"}

@@ -1,1 +0,1 @@

{"version":3,"file":"its-first.d.ts","sourceRoot":"","sources":["../../src/consumption/its-first.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAMhE"}
{"version":3,"file":"its-first.d.ts","sourceRoot":"","sources":["../../src/consumption/its-first.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAQhE"}

@@ -5,3 +5,3 @@ /**

*
* @typeParam T A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @typeParam R A type of reduced value.

@@ -8,0 +8,0 @@ * @param iterable An iterable to reduce values of.

@@ -1,1 +0,1 @@

{"version":3,"file":"its-reduction.d.ts","sourceRoot":"","sources":["../../src/consumption/its-reduction.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAC/C,YAAY,EAAE,CAAC,GAChB,CAAC,CAMH"}
{"version":3,"file":"its-reduction.d.ts","sourceRoot":"","sources":["../../src/consumption/its-reduction.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC7B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,EAC/C,YAAY,EAAE,CAAC,GAChB,CAAC,CAOH"}
/**
* Tests whether at least one element of the given `iterable` passes the test implemented by the provided function.
*
* @typeParam T A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @param iterable An iterable to test elements of.

@@ -6,0 +6,0 @@ * @param test A predicate function to test each element. Returns `false` to continue tests, or `true` to stop it

@@ -1,1 +0,1 @@

{"version":3,"file":"its-some.d.ts","sourceRoot":"","sources":["../../src/consumption/its-some.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACrB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,OAAO,CAMT"}
{"version":3,"file":"its-some.d.ts","sourceRoot":"","sources":["../../src/consumption/its-some.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACrB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,OAAO,CAgBT"}

@@ -7,2 +7,6 @@ /**

/**
* A key of {@link PushIterable} iteration method.
*/
export declare const PushIterator__symbol: unique symbol;
/**
* An iterable implementing push iteration protocol.

@@ -19,3 +23,40 @@ *

[Symbol.iterator](): PushIterator<T>;
/**
* Iterates over elements of this push iterable.
*
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either
* `true` or `false`.
*
* Calling this method with `accept` parameter is a faster alternative to creating a push iterator and iterating with
* it.
*
* Calling this method without arguments is the same as calling `[Symbol.iterator]()` one.
*
* @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 to continue iteration with. If `accept` returned `false` then further iteration
* won't be possible with returned iterator.
*/
[PushIterator__symbol](accept?: PushIterator.Acceptor<T>): PushIterator<T>;
}
export declare namespace PushIterable {
/**
* A signature of function conforming to push iteration protocol.
*
* Used as `PushIterable[PushIterator__symbol]` method implementation when passed to {@link makePushIterable}
* function.
*
* @typeParam T Iterated elements type.
*/
type Iterate<T> =
/**
* @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 to continue iteration with. If `accept` returned `false` then further iteration
* won't be possible with returned iterator.
*/
(this: void, accept?: PushIterator.Acceptor<T>) => PushIterator<T>;
}
//# sourceMappingURL=push-iterable.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"push-iterable.d.ts","sourceRoot":"","sources":["../src/push-iterable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAElD;;;;OAIG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;CAEtC"}
{"version":3,"file":"push-iterable.d.ts","sourceRoot":"","sources":["../src/push-iterable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,oBAAoB,eAA0C,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAElD;;;;OAIG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAErC;;;;;;;;;;;;;;;;OAgBG;IACH,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;CAE5E;AAED,yBAAiB,YAAY,CAAC;IAE5B;;;;;;;OAOG;IACH,KAAY,OAAO,CAAC,CAAC;IACrB;;;;;;OAMG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC;CAExE"}

@@ -14,33 +14,11 @@ /**

/**
* Iterates over elements of this iterator.
* Checks whether iteration is over.
*
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned `false`.
*
* Resumes iteration on subsequent calls.
*
* Note that this method does not require `this` context and can be called as a function.
*
* @param accept A function to push iterated elements to. Accepts iterated element as its only parameter. May return
* `false` to stop iteration.
*
* @returns `true` if there are more elements to iterate, or `false` otherwise. The former is possible only when
* iteration stopped, i.e. `accept` returned `false`.
* @returns `true` is there is nothing to iterate any more, or `false` if iteration is still possible.
*/
forNext(this: void, accept: PushIterator.Acceptor<T>): boolean;
isOver(): boolean;
}
/**
* Either {@link PushIterator push} iterator or raw one.
*
* Functions of this library work with both iterator types.
*
* @typeParam T Iterated elements type.
*/
export declare type PushOrRawIterator<T> = PushIterator<T> | {
forNext?: undefined;
next(): IteratorResult<T>;
};
export declare namespace PushIterator {
/**
* A signature of iterated elements pusher function conforming to {@link PushIterator.forNext push iteration
* protocol}.
* A signature of iterated elements pusher function conforming to push iteration protocol.
*

@@ -59,5 +37,5 @@ * @typeParam T Iterated elements type.

/**
* A signature of a function accepting {@link PushIterator.forNext iterated elements}.
* A signature of a function accepting iterated elements.
*
* It is able to prevent further iteration by returning `false`.
* It is able to suspend iteration by returning `true`, or to stop it by returning `false`.
*

@@ -68,3 +46,3 @@ * @typeParam T Iterated elements type.

/**
* A signature of a function accepting each {@link PushIterator.forNext iterated element} unconditionally.
* A signature of a function accepting each iterated element unconditionally.
*

@@ -79,5 +57,12 @@ * @typeParam T Iterated elements type.

/**
* A signature of a function accepting {@link PushIterator.forNext iterated elements} and able to prevent further
* A signature of a function accepting iterated elements and able to suspend or stop further iteration.
*
* When this function returns `true`, the iteration is suspended. I.e. the no more elements would be pushed to this
* function, but the iteration method (`[PushIterator__symbol]`) would return an iterator that can be used to resume
* iteration.
*
* When this function returns `false`, the iteration is stopped. I.e. the no more elements would be pushed to this
* function, and the iteration method (`[PushIterator__symbol]`) would return an empty iterator. I.e. the one with
* its {@link PushIterator.isOver} method always returning `true`.
*
* @typeParam T Iterated elements type.

@@ -89,3 +74,3 @@ */

*
* @returns `false` to prevent further iteration. No more element will be pushed to acceptor after that.
* @returns `true` to suspend iteration, or `false` to stop it.
*/

@@ -92,0 +77,0 @@ (this: void, element: T) => boolean;

@@ -1,1 +0,1 @@

{"version":3,"file":"push-iterator.d.ts","sourceRoot":"","sources":["../src/push-iterator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3E,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAErC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CAEhE;AAED;;;;;;GAMG;AACH,oBAAY,iBAAiB,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG;IACnD,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,IAAI,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;CAC3B,CAAC;AAEF,yBAAiB,YAAY,CAAC;IAE5B;;;;;OAKG;IACH,KAAY,MAAM,CAAC,CAAC;IACpB;;;;;;OAMG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAEjD;;;;;;OAMG;IACH,KAAY,QAAQ,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEhE;;;;OAIG;IACH,KAAY,YAAY,CAAC,CAAC;IAC1B;;OAEG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAErC;;;;;OAKG;IACH,KAAY,gBAAgB,CAAC,CAAC;IAC9B;;;;OAIG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC;CAEzC"}
{"version":3,"file":"push-iterator.d.ts","sourceRoot":"","sources":["../src/push-iterator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;IAE3E,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC;IAErC;;;;OAIG;IACH,MAAM,IAAI,OAAO,CAAC;CAEnB;AAED,yBAAiB,YAAY,CAAC;IAE5B;;;;OAIG;IACH,KAAY,MAAM,CAAC,CAAC;IACpB;;;;;;OAMG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAEjD;;;;;;OAMG;IACH,KAAY,QAAQ,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEhE;;;;OAIG;IACH,KAAY,YAAY,CAAC,CAAC;IAC1B;;OAEG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAErC;;;;;;;;;;;;OAYG;IACH,KAAY,gBAAgB,CAAC,CAAC;IAC9B;;;;OAIG;IACC,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,CAAC;CAEzC"}

@@ -18,3 +18,3 @@ import type { PushIterable } from '../push-iterable';

*
* @typeParam T A type of array elements
* @typeParam T A type of array elements.
* @typeParam R Target type.

@@ -21,0 +21,0 @@ * @param array A source array.

@@ -1,1 +0,1 @@

{"version":3,"file":"filter-array.d.ts","sourceRoot":"","sources":["../../src/transformation/filter-array.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACtC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/C,YAAY,CAAC,CAAC,CAAC,CAAC"}
{"version":3,"file":"filter-array.d.ts","sourceRoot":"","sources":["../../src/transformation/filter-array.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACtC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/C,YAAY,CAAC,CAAC,CAAC,CAAC"}

@@ -18,3 +18,3 @@ import type { PushIterable } from '../push-iterable';

*
* @typeParam T A type of source elements
* @typeParam T A type of source elements.
* @typeParam R Target type.

@@ -21,0 +21,0 @@ * @param source A source iterable.

@@ -1,1 +0,1 @@

{"version":3,"file":"filter-it.d.ts","sourceRoot":"","sources":["../../src/transformation/filter-it.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACtB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACnC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/C,YAAY,CAAC,CAAC,CAAC,CAAC"}
{"version":3,"file":"filter-it.d.ts","sourceRoot":"","sources":["../../src/transformation/filter-it.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACtB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,GAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;AAEnB;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,EACnC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,OAAO,IAAI,CAAC,GAC/C,YAAY,CAAC,CAAC,CAAC,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"flat-map-array.d.ts","sourceRoot":"","sources":["../../src/transformation/flat-map-array.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC7B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GACjD,YAAY,CAAC,CAAC,CAAC,CAAC"}
{"version":3,"file":"flat-map-array.d.ts","sourceRoot":"","sources":["../../src/transformation/flat-map-array.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAEhF;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC7B,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GACjD,YAAY,CAAC,CAAC,CAAC,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"flat-map-it.d.ts","sourceRoot":"","sources":["../../src/transformation/flat-map-it.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC1B,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GACjD,YAAY,CAAC,CAAC,CAAC,CAAC"}
{"version":3,"file":"flat-map-it.d.ts","sourceRoot":"","sources":["../../src/transformation/flat-map-it.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC1B,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GACjD,YAAY,CAAC,CAAC,CAAC,CAAC"}

@@ -1,1 +0,1 @@

{"version":3,"file":"map-array.d.ts","sourceRoot":"","sources":["../../src/transformation/map-array.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GACvC,YAAY,CAAC,CAAC,CAAC,CAwCjB"}
{"version":3,"file":"map-array.d.ts","sourceRoot":"","sources":["../../src/transformation/map-array.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GACvC,YAAY,CAAC,CAAC,CAAC,CAEjB"}

@@ -1,1 +0,1 @@

{"version":3,"file":"map-it.d.ts","sourceRoot":"","sources":["../../src/transformation/map-it.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACtB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GACvC,YAAY,CAAC,CAAC,CAAC,CAUjB"}
{"version":3,"file":"map-it.d.ts","sourceRoot":"","sources":["../../src/transformation/map-it.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EACtB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GACvC,YAAY,CAAC,CAAC,CAAC,CAOjB"}

@@ -6,10 +6,10 @@ 'use strict';

/**
* Constructs iterator over elements of the given `iterable`.
*
* Calls `iterable[Symbol.iterator]()` and returns its result.
*
* @param iterable An iterable to construct iterator of.
*
* @returns Either push or raw iterable.
* A key of {@link PushIterable} iteration method.
*/
const PushIterator__symbol = ( /*#__PURE__*/Symbol('push-iterator'));
function isPushIterable(iterable) {
return !!iterable[PushIterator__symbol];
}
function iteratorOf(iterable) {

@@ -20,103 +20,24 @@ return iterable[Symbol.iterator]();

/**
* @internal
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
function PushIterator$iterator() {
return this;
}
/**
* @internal
* 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 PushIterator$next() {
for (;;) {
let result;
const done = !this.forNext(value => {
result = { value };
return false;
});
if (result) {
return result;
}
if (done) {
return { done: true };
}
}
}
/**
* @internal
*/
const arrayIterator = (array) => {
let i = 0;
function makePushIterable(iterate) {
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => i < array.length ? { value: array[i++] } : { done: true },
forNext(accept) {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(array[i++]);
if (i >= array.length) {
return false;
}
if (goOn === false) {
return true;
}
}
},
[Symbol.iterator]: PushIterable$iterator,
[PushIterator__symbol]: iterate,
};
};
/**
* @internal
*/
const noneIterator = {
[Symbol.iterator]: PushIterator$iterator,
next: () => ({ done: true }),
forNext: _accept /* Unused parameter to prevent deoptimization */ => false,
};
/**
* @internal
*/
function oneValueIterator(value) {
let done = false;
return {
[Symbol.iterator]: PushIterator$iterator,
next() {
if (done) {
return { done };
}
done = true;
return { value };
},
forNext(accept) {
if (!done) {
done = true;
accept(value);
}
return false;
},
};
}
/**
* @internal
*/
function toPushIterator(it) {
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => it.next(),
forNext(accept) {
for (;;) {
const res = it.next();
if (res.done) {
return false;
}
if (accept(res.value) === false) {
return true;
}
}
},
};
function PushIterable$iterator() {
return this[PushIterator__symbol]();
}

@@ -129,12 +50,19 @@

/**
* Starts iteration over the given `iterable`.
* 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 An iterable or push iterable to iterate over.
* @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.
*
* @return A push iterator iterating over the given iterable.
* @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 itsIterator(iterable) {
const it = iteratorOf(iterable);
return it.forNext ? it : toPushIterator(it);
function pushIterated(iterable, accept) {
return !iterable[PushIterator__symbol](accept).isOver();
}

@@ -147,5 +75,6 @@

/**
* Creates push iterator implementation.
* Creates a push iterator implementation.
*
* @param forNext A function iterating over elements conforming to {@link PushIterator.forNext} requirement.
* @typeParam T Iterated elements type.
* @param forNext A function iterating over elements conforming to push iteration protocol.
*

@@ -155,59 +84,66 @@ * @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,
forNext,
isOver: () => over,
};
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
function PushIterator$iterator() {
return this;
}
/**
* Returns a {@link PushIterator push iterable iterator} without elements.
*
* @typeParam T Iterated elements type.
*
* @returns Empty push iterable and push iterator instance.
* @internal
*/
function overNone() {
return noneIterator;
function PushIterator$next() {
for (;;) {
let result;
const over = !pushIterated(this, value => {
result = { value };
return true;
});
if (result) {
return result;
}
if (over) {
return { done: true };
}
}
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
function PushIterator$noNext() {
return { done: true };
}
/**
* 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.
* @internal
*/
function overOne(value) {
return { [Symbol.iterator]: () => oneValueIterator(value) };
function PushIterator$dontIterate(_accept) {
/* do not iterate */
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
/**
* 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 array.length > 1
? { [Symbol.iterator]: () => arrayIterator(array) }
: (!array.length
? overNone()
: overOne(array[0]));
}
const emptyPushIterator = {
[Symbol.iterator]: PushIterator$iterator,
[PushIterator__symbol](_accept) {
return this;
},
next: () => ({ done: true }),
isOver: () => true,
};

@@ -219,54 +155,71 @@ /**

/**
* Creates a {@link PushIterable push iterable} over elements of the given raw iterable.
* Iterates over the head elements of the given push iterable.
*
* @typeParam T Iterated elements type.
* @param source Source iterable to iterate over elements of.
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either
* `true` or `false`.
*
* @returns New push iterable over elements of the given `source`.
*/
function overIterable(source) {
return Array.isArray(source)
? overArray(source)
: { [Symbol.iterator]: () => toPushIterator(source[Symbol.iterator]()) };
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
/**
* Creates a {@link PushIterable push iterable} over elements of other iterables.
* Calling this function is the same as calling `iterable[PushIterator__symbol](accept)`.
*
* @typeParam T Iterated elements type.
* @param sources Source iterables to iterate over elements of.
* @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 New push iterable over elements of the given `sources`.
* @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 overElementsOf(...sources) {
return sources.length > 1
? { [Symbol.iterator]: () => makePushIterator(subElementsPusher(sources)) }
: (sources.length
? overIterable(sources[0])
: overNone());
function pushHead(iterable, accept) {
return iterable[PushIterator__symbol](accept);
}
/**
* @internal
*/
function subElementsPusher(sources) {
let i = 0;
let forNext = itsIterator(sources[0]).forNext;
function iterateOverArray(array) {
return accept => {
for (;;) {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNext(element => goOn = accept(element))) {
if (++i >= sources.length) {
let i = 0;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(array[i++]);
if (i >= array.length || goOn === false) {
return false;
}
forNext = itsIterator(sources[i]).forNext;
if (goOn === true) {
return true;
}
}
if (goOn === false) {
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 < array.length) {
return { value: array[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,
};
};

@@ -276,15 +229,15 @@ }

/**
* Creates a {@link PushIterable push iterable} over many values.
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
/**
* Creates a {@link PushIterable push iterable} over elements of array-like structure.
*
* @typeParam T Iterated elements value type.
* @param values Values to iterate over.
* @typeParam T Array elements type.
* @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc.
*
* @returns New push iterable over the given values.
* @returns New push iterable over array elements.
*/
function overMany(...values) {
return values.length > 1
? overArray(values)
: (values.length
? overOne(values[0])
: overNone());
function overArray(array) {
return makePushIterable(iterateOverArray(array));
}

@@ -297,31 +250,35 @@

/**
* Creates a {@link PushIterable push iterable} over elements of array-like structure in reverse order.
* Iterates over elements of the given iterable.
*
* @typeParam T Array elements type.
* @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc.
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either
* `true` or `false`.
*
* @returns New push iterable over array elements in reverse order.
* 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 reverseArray(array) {
return { [Symbol.iterator]: () => reverseArrayIterator(array) };
}
/**
* @internal
*/
function reverseArrayIterator(array) {
let i = array.length - 1;
return makePushIterator(accept => {
if (i < 0) {
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;
}
for (;;) {
const goOn = accept(array[i--]);
if (i < 0) {
return false;
}
if (goOn === false) {
return true;
}
const status = accept(next.value);
if (typeof status === 'boolean') {
return status;
}
});
}
}

@@ -342,26 +299,4 @@

function itsEach(iterable, action) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEach(forNext, action) : rawEach(it, action);
itsIterated(iterable, element => { action(element); });
}
/**
* @internal
*/
function pushedEach(forNext, action) {
forNext(element => {
action(element);
});
}
/**
* @internal
*/
function rawEach(it, action) {
for (;;) {
const next = it.next();
if (next.done) {
return;
}
action(next.value);
}
}

@@ -377,5 +312,7 @@ /**

function itsElements(source, convert = itsElements$defaultConverter) {
if (isPushIterable(source)) {
return pushedElements(source, convert);
}
const it = iteratorOf(source);
const forNext = it.forNext;
return forNext ? pushedElements(forNext, convert) : Array.from(source, convert);
return isPushIterable(it) ? pushedElements(it, convert) : Array.from(source, convert);
}

@@ -385,7 +322,5 @@ /**

*/
function pushedElements(forNext, convert) {
function pushedElements(it, convert) {
const result = [];
forNext(element => {
result.push(convert(element));
});
pushIterated(it, element => { result.push(convert(element)); });
return result;

@@ -406,5 +341,7 @@ }

function itsEmpty(iterable) {
if (isPushIterable(iterable)) {
return pushedEmpty(iterable);
}
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEmpty(forNext) : !!it.next().done;
return isPushIterable(it) ? pushedEmpty(it) : !!it.next().done;
}

@@ -414,5 +351,5 @@ /**

*/
function pushedEmpty(forNext) {
function pushedEmpty(it) {
let isEmpty = true;
forNext(_element /* Unused parameter to prevent deoptimization */ => isEmpty = false);
pushIterated(it, _element /* Unused parameter to prevent deoptimization */ => isEmpty = false);
return isEmpty;

@@ -437,28 +374,40 @@ }

function itsEvery(iterable, test) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEvery(forNext, test) : rawEvery(it, test);
}
/**
* @internal
*/
function pushedEvery(forNext, test) {
let allMatch = true;
forNext(element => allMatch = !!test(element));
itsIterated(iterable, element => {
allMatch = !!test(element);
if (!allMatch) {
return false;
}
return;
});
return allMatch;
}
/**
* @internal
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
function rawEvery(it, test) {
let allMatch = true;
for (;;) {
const next = it.next();
if (next.done) {
return allMatch;
/**
* Searches for the value in `iterable`.
*
* @typeParam T Iterated elements type.
* @typeParam R 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;
}
if (!(allMatch = !!test(next.value))) {
return false;
}
}
return;
});
return find;
}

@@ -479,5 +428,7 @@

function itsFirst(iterable) {
if (isPushIterable(iterable)) {
return pushedFirst(iterable);
}
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedFirst(forNext) : rawFirst(it);
return isPushIterable(it) ? pushedFirst(it) : rawFirst(it);
}

@@ -487,5 +438,5 @@ /**

*/
function pushedFirst(forNext) {
function pushedFirst(it) {
let first;
forNext(element => {
pushIterated(it, element => {
first = element;

@@ -505,2 +456,53 @@ return false;

/**
* @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

@@ -510,6 +512,96 @@ * @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 A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @typeParam R A type of reduced value.

@@ -524,27 +616,6 @@ * @param iterable An iterable to reduce values of.

function itsReduction(iterable, reducer, initialValue) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedReduction(forNext, reducer, initialValue) : rawReduction(it, reducer, initialValue);
}
/**
* @internal
*/
function pushedReduction(forNext, reducer, reduced) {
forNext(element => {
reduced = reducer(reduced, element);
});
let reduced = initialValue;
itsIterated(iterable, element => { reduced = reducer(reduced, element); });
return reduced;
}
/**
* @internal
*/
function rawReduction(it, reducer, reduced) {
for (;;) {
const next = it.next();
if (next.done) {
return reduced;
}
reduced = reducer(reduced, next.value);
}
}

@@ -558,3 +629,3 @@ /**

*
* @typeParam T A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @param iterable An iterable to test elements of.

@@ -568,28 +639,237 @@ * @param test A predicate function to test each element. Returns `false` to continue tests, or `true` to stop it

function itsSome(iterable, test) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedSome(forNext, test) : rawSome(it, 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 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)
: makePushIterable(iterateOverRawIterable(iterable));
}
/**
* @internal
*/
function pushedSome(forNext, test) {
let someMatches = false;
forNext(element => !(someMatches = !!test(element)));
return someMatches;
function iterateOverRawIterable(iterable) {
return accept => {
const it = iteratorOf(iterable);
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 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 rawSome(it, test) {
let someMatches = false;
for (;;) {
const next = it.next();
if (next.done) {
return someMatches;
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 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();
}
if ((someMatches = !!test(next.value))) {
return true;
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,
};
};
}

@@ -620,34 +900,59 @@

function filterArray(array, test) {
if (!array.length) {
return overNone();
}
return {
[Symbol.iterator]() {
let i = 0;
return {
[Symbol.iterator]: PushIterator$iterator,
next() {
for (;;) {
if (i >= array.length) {
return { done: true };
}
const value = array[i++];
if (test(value)) {
return { value };
}
return makePushIterable(iterateOverFilteredArray(array, test));
}
/**
* @internal
*/
function iterateOverFilteredArray(array, test) {
return accept => {
let i = 0;
const forNext = (accept) => {
for (;;) {
if (i >= array.length) {
return false;
}
const value = array[i++];
if (test(value)) {
const status = accept(value);
if (typeof status === 'boolean') {
return status;
}
},
forNext(accept) {
for (;;) {
if (i >= array.length) {
return false;
}
const value = array[i++];
if (test(value) && accept(value) === false) {
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 = () => {
for (;;) {
if (i >= array.length) {
over = true;
iterate = PushIterator$dontIterate;
next = PushIterator$noNext;
return { done: true };
}
const value = array[i++];
if (test(value)) {
return { value };
}
}
};
return {
[Symbol.iterator]: PushIterator$iterator,
[PushIterator__symbol](accept) {
iterate(accept);
return this;
},
next: () => next(),
isOver: () => over,
};
};

@@ -661,9 +966,6 @@ }

function filterIt(source, test) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? filterPusher(forNext, test) : filterRawPusher(it, test));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? filterPusher(source, test) : filterRawPusher(source, test);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -673,4 +975,13 @@ /**

*/
function filterPusher(forNext, test) {
return accept => forNext(element => !test(element) || accept(element));
function filterPusher(source, test) {
return accept => {
const tail = pushHead(source, element => {
if (test(element)) {
return accept(element);
}
return;
});
source = tail;
return !tail.isOver();
};
}

@@ -680,3 +991,7 @@ /**

*/
function filterRawPusher(it, test) {
function filterRawPusher(source, test) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return filterPusher(it, test);
}
return accept => {

@@ -689,4 +1004,7 @@ for (;;) {

const value = next.value;
if (test(value) && accept(value) === false) {
return true;
if (test(value)) {
const status = accept(value);
if (typeof status === 'boolean') {
return status;
}
}

@@ -707,6 +1025,3 @@ }

function flatMapArray(array, convert = flatMapIt$defaultConverter) {
const length = array.length;
return length > 1
? { [Symbol.iterator]: () => makePushIterator(flatMapArrayPusher(array, convert)) }
: (length ? overIterable(convert(array[0])) : overNone());
return makePushIterable(iterateOverFlattenedArray(array, convert));
}

@@ -716,19 +1031,31 @@ /**

*/
function flatMapArrayPusher(array, convert) {
let cIt = itsIterator(convert(array[0]));
let index = 1;
function iterateOverFlattenedArray(array, convert) {
return accept => {
for (;;) {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!cIt.forNext(element => goOn = accept(element))) {
if (index >= array.length) {
return false;
let i = 0;
let subs;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
if (!subs) {
subs = convert(array[i]);
}
for (;;) {
let status;
const subsTail = itsHead(subs, element => status = accept(element));
if (subsTail.isOver()) {
if (++i >= array.length) {
return false;
}
subs = convert(array[i]);
}
cIt = itsIterator(convert(array[index++]));
else {
subs = subsTail;
}
if (typeof status === 'boolean') {
return status;
}
}
if (goOn === false) {
return true;
}
}
};
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
};

@@ -742,9 +1069,6 @@ }

function flatMapIt(source, convert = flatMapIt$defaultConverter) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? flatMapPusher(forNext, convert) : flatMapRawPusher(it, convert));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? flatMapPusher(source, convert) : flatMapRawPusher(source, convert);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -754,13 +1078,15 @@ /**

*/
function flatMapPusher(forNext, convert) {
let forNextSub;
function flatMapPusher(source, convert) {
let subs;
let lastSrc = false;
return accept => {
for (;;) {
while (!forNextSub) {
if (!forNext(src => {
forNextSub = itsIterator(convert(src)).forNext;
return false;
})) {
if (!forNextSub) {
while (!subs) {
const sourceTail = pushHead(source, src => {
subs = convert(src);
return true;
});
source = sourceTail;
if (sourceTail.isOver()) {
if (!subs) {
return false;

@@ -772,5 +1098,6 @@ }

// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNextSub(element => goOn = accept(element))) {
forNextSub = undefined;
let status;
const subsTail = itsHead(subs, element => status = accept(element));
if (subsTail.isOver()) {
subs = undefined;
if (lastSrc) {

@@ -780,5 +1107,8 @@ return false;

}
if (goOn === false) {
return true;
else {
subs = subsTail;
}
if (typeof status === 'boolean') {
return status;
}
}

@@ -790,7 +1120,11 @@ };

*/
function flatMapRawPusher(it, convert) {
let forNextSub;
function flatMapRawPusher(source, convert) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return flatMapPusher(it, convert);
}
let subs;
return accept => {
for (;;) {
if (!forNextSub) {
if (!subs) {
const next = it.next();

@@ -800,12 +1134,11 @@ if (next.done) {

}
forNextSub = itsIterator(convert(next.value)).forNext;
subs = convert(next.value);
}
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNextSub(element => goOn = accept(element))) {
forNextSub = undefined;
let status;
const subsTail = itsHead(subs, element => status = accept(element));
subs = subsTail.isOver() ? undefined : subsTail;
if (typeof status === 'boolean') {
return status;
}
if (goOn === false) {
return true;
}
}

@@ -831,28 +1164,54 @@ };

function mapArray(array, convert) {
const length = array.length;
if (length <= 1) {
return length ? overOne(convert(array[0])) : overNone();
}
return {
[Symbol.iterator]() {
let i = 0;
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => i < array.length ? { value: convert(array[i++]) } : { done: true },
forNext(accept) {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(convert(array[i++]));
if (i >= array.length) {
return false;
}
if (goOn === false) {
return true;
}
}
},
};
},
return makePushIterable(iterateOverMappedArray(array, convert));
}
/**
* @internal
*/
function iterateOverMappedArray(array, convert) {
return accept => {
let i = 0;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
for (;;) {
const status = accept(convert(array[i++]));
if (i >= array.length) {
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 < array.length) {
return { value: convert(array[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,
};
};

@@ -878,9 +1237,6 @@ }

function mapIt(source, convert) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? mapPusher(forNext, convert) : mapRawPusher(it, convert));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? mapPusher(source, convert) : mapRawPusher(source, convert);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -890,4 +1246,8 @@ /**

*/
function mapPusher(forNext, convert) {
return accept => forNext(element => accept(convert(element)));
function mapPusher(source, convert) {
return accept => {
const tail = pushHead(source, element => accept(convert(element)));
source = tail;
return !tail.isOver();
};
}

@@ -897,3 +1257,7 @@ /**

*/
function mapRawPusher(it, convert) {
function mapRawPusher(source, convert) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return mapPusher(it, convert);
}
return accept => {

@@ -905,4 +1269,5 @@ for (;;) {

}
if (accept(convert(next.value)) === false) {
return true;
const status = accept(convert(next.value));
if (typeof status === 'boolean') {
return status;
}

@@ -928,2 +1293,3 @@ }

exports.PushIterator__symbol = PushIterator__symbol;
exports.filterArray = filterArray;

@@ -933,2 +1299,3 @@ exports.filterIt = filterIt;

exports.flatMapIt = flatMapIt;
exports.isPushIterable = isPushIterable;
exports.iteratorOf = iteratorOf;

@@ -939,6 +1306,11 @@ exports.itsEach = itsEach;

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;

@@ -955,3 +1327,5 @@ exports.mapArray = mapArray;

exports.overOne = overOne;
exports.pushHead = pushHead;
exports.pushIterated = pushIterated;
exports.reverseArray = reverseArray;
//# sourceMappingURL=push-iterator.js.map
/**
* Constructs iterator over elements of the given `iterable`.
*
* Calls `iterable[Symbol.iterator]()` and returns its result.
*
* @param iterable An iterable to construct iterator of.
*
* @returns Either push or raw iterable.
* A key of {@link PushIterable} iteration method.
*/
const PushIterator__symbol = ( /*#__PURE__*/Symbol('push-iterator'));
function isPushIterable(iterable) {
return !!iterable[PushIterator__symbol];
}
function iteratorOf(iterable) {

@@ -15,103 +15,24 @@ return iterable[Symbol.iterator]();

/**
* @internal
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
function PushIterator$iterator() {
return this;
}
/**
* @internal
* 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 PushIterator$next() {
for (;;) {
let result;
const done = !this.forNext(value => {
result = { value };
return false;
});
if (result) {
return result;
}
if (done) {
return { done: true };
}
}
}
/**
* @internal
*/
const arrayIterator = (array) => {
let i = 0;
function makePushIterable(iterate) {
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => i < array.length ? { value: array[i++] } : { done: true },
forNext(accept) {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(array[i++]);
if (i >= array.length) {
return false;
}
if (goOn === false) {
return true;
}
}
},
[Symbol.iterator]: PushIterable$iterator,
[PushIterator__symbol]: iterate,
};
};
/**
* @internal
*/
const noneIterator = {
[Symbol.iterator]: PushIterator$iterator,
next: () => ({ done: true }),
forNext: _accept /* Unused parameter to prevent deoptimization */ => false,
};
/**
* @internal
*/
function oneValueIterator(value) {
let done = false;
return {
[Symbol.iterator]: PushIterator$iterator,
next() {
if (done) {
return { done };
}
done = true;
return { value };
},
forNext(accept) {
if (!done) {
done = true;
accept(value);
}
return false;
},
};
}
/**
* @internal
*/
function toPushIterator(it) {
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => it.next(),
forNext(accept) {
for (;;) {
const res = it.next();
if (res.done) {
return false;
}
if (accept(res.value) === false) {
return true;
}
}
},
};
function PushIterable$iterator() {
return this[PushIterator__symbol]();
}

@@ -124,12 +45,19 @@

/**
* Starts iteration over the given `iterable`.
* 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 An iterable or push iterable to iterate over.
* @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.
*
* @return A push iterator iterating over the given iterable.
* @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 itsIterator(iterable) {
const it = iteratorOf(iterable);
return it.forNext ? it : toPushIterator(it);
function pushIterated(iterable, accept) {
return !iterable[PushIterator__symbol](accept).isOver();
}

@@ -142,5 +70,6 @@

/**
* Creates push iterator implementation.
* Creates a push iterator implementation.
*
* @param forNext A function iterating over elements conforming to {@link PushIterator.forNext} requirement.
* @typeParam T Iterated elements type.
* @param forNext A function iterating over elements conforming to push iteration protocol.
*

@@ -150,59 +79,66 @@ * @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,
forNext,
isOver: () => over,
};
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
function PushIterator$iterator() {
return this;
}
/**
* Returns a {@link PushIterator push iterable iterator} without elements.
*
* @typeParam T Iterated elements type.
*
* @returns Empty push iterable and push iterator instance.
* @internal
*/
function overNone() {
return noneIterator;
function PushIterator$next() {
for (;;) {
let result;
const over = !pushIterated(this, value => {
result = { value };
return true;
});
if (result) {
return result;
}
if (over) {
return { done: true };
}
}
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
function PushIterator$noNext() {
return { done: true };
}
/**
* 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.
* @internal
*/
function overOne(value) {
return { [Symbol.iterator]: () => oneValueIterator(value) };
function PushIterator$dontIterate(_accept) {
/* do not iterate */
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
* @internal
*/
/**
* 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 array.length > 1
? { [Symbol.iterator]: () => arrayIterator(array) }
: (!array.length
? overNone()
: overOne(array[0]));
}
const emptyPushIterator = {
[Symbol.iterator]: PushIterator$iterator,
[PushIterator__symbol](_accept) {
return this;
},
next: () => ({ done: true }),
isOver: () => true,
};

@@ -214,54 +150,71 @@ /**

/**
* Creates a {@link PushIterable push iterable} over elements of the given raw iterable.
* Iterates over the head elements of the given push iterable.
*
* @typeParam T Iterated elements type.
* @param source Source iterable to iterate over elements of.
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either
* `true` or `false`.
*
* @returns New push iterable over elements of the given `source`.
*/
function overIterable(source) {
return Array.isArray(source)
? overArray(source)
: { [Symbol.iterator]: () => toPushIterator(source[Symbol.iterator]()) };
}
/**
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
/**
* Creates a {@link PushIterable push iterable} over elements of other iterables.
* Calling this function is the same as calling `iterable[PushIterator__symbol](accept)`.
*
* @typeParam T Iterated elements type.
* @param sources Source iterables to iterate over elements of.
* @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 New push iterable over elements of the given `sources`.
* @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 overElementsOf(...sources) {
return sources.length > 1
? { [Symbol.iterator]: () => makePushIterator(subElementsPusher(sources)) }
: (sources.length
? overIterable(sources[0])
: overNone());
function pushHead(iterable, accept) {
return iterable[PushIterator__symbol](accept);
}
/**
* @internal
*/
function subElementsPusher(sources) {
let i = 0;
let forNext = itsIterator(sources[0]).forNext;
function iterateOverArray(array) {
return accept => {
for (;;) {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNext(element => goOn = accept(element))) {
if (++i >= sources.length) {
let i = 0;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(array[i++]);
if (i >= array.length || goOn === false) {
return false;
}
forNext = itsIterator(sources[i]).forNext;
if (goOn === true) {
return true;
}
}
if (goOn === false) {
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 < array.length) {
return { value: array[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,
};
};

@@ -271,15 +224,15 @@ }

/**
* Creates a {@link PushIterable push iterable} over many values.
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
/**
* Creates a {@link PushIterable push iterable} over elements of array-like structure.
*
* @typeParam T Iterated elements value type.
* @param values Values to iterate over.
* @typeParam T Array elements type.
* @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc.
*
* @returns New push iterable over the given values.
* @returns New push iterable over array elements.
*/
function overMany(...values) {
return values.length > 1
? overArray(values)
: (values.length
? overOne(values[0])
: overNone());
function overArray(array) {
return makePushIterable(iterateOverArray(array));
}

@@ -292,31 +245,35 @@

/**
* Creates a {@link PushIterable push iterable} over elements of array-like structure in reverse order.
* Iterates over elements of the given iterable.
*
* @typeParam T Array elements type.
* @param array An array-like structure. E.g. `Array`, DOM `NodeList`, etc.
* Calls `accept` method for each iterated element until there are elements to iterate, or `accept` returned either
* `true` or `false`.
*
* @returns New push iterable over array elements in reverse order.
* 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 reverseArray(array) {
return { [Symbol.iterator]: () => reverseArrayIterator(array) };
}
/**
* @internal
*/
function reverseArrayIterator(array) {
let i = array.length - 1;
return makePushIterator(accept => {
if (i < 0) {
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;
}
for (;;) {
const goOn = accept(array[i--]);
if (i < 0) {
return false;
}
if (goOn === false) {
return true;
}
const status = accept(next.value);
if (typeof status === 'boolean') {
return status;
}
});
}
}

@@ -337,26 +294,4 @@

function itsEach(iterable, action) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEach(forNext, action) : rawEach(it, action);
itsIterated(iterable, element => { action(element); });
}
/**
* @internal
*/
function pushedEach(forNext, action) {
forNext(element => {
action(element);
});
}
/**
* @internal
*/
function rawEach(it, action) {
for (;;) {
const next = it.next();
if (next.done) {
return;
}
action(next.value);
}
}

@@ -372,5 +307,7 @@ /**

function itsElements(source, convert = itsElements$defaultConverter) {
if (isPushIterable(source)) {
return pushedElements(source, convert);
}
const it = iteratorOf(source);
const forNext = it.forNext;
return forNext ? pushedElements(forNext, convert) : Array.from(source, convert);
return isPushIterable(it) ? pushedElements(it, convert) : Array.from(source, convert);
}

@@ -380,7 +317,5 @@ /**

*/
function pushedElements(forNext, convert) {
function pushedElements(it, convert) {
const result = [];
forNext(element => {
result.push(convert(element));
});
pushIterated(it, element => { result.push(convert(element)); });
return result;

@@ -401,5 +336,7 @@ }

function itsEmpty(iterable) {
if (isPushIterable(iterable)) {
return pushedEmpty(iterable);
}
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEmpty(forNext) : !!it.next().done;
return isPushIterable(it) ? pushedEmpty(it) : !!it.next().done;
}

@@ -409,5 +346,5 @@ /**

*/
function pushedEmpty(forNext) {
function pushedEmpty(it) {
let isEmpty = true;
forNext(_element /* Unused parameter to prevent deoptimization */ => isEmpty = false);
pushIterated(it, _element /* Unused parameter to prevent deoptimization */ => isEmpty = false);
return isEmpty;

@@ -432,28 +369,40 @@ }

function itsEvery(iterable, test) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedEvery(forNext, test) : rawEvery(it, test);
}
/**
* @internal
*/
function pushedEvery(forNext, test) {
let allMatch = true;
forNext(element => allMatch = !!test(element));
itsIterated(iterable, element => {
allMatch = !!test(element);
if (!allMatch) {
return false;
}
return;
});
return allMatch;
}
/**
* @internal
* @packageDocumentation
* @module @proc7ts/push-iterator
*/
function rawEvery(it, test) {
let allMatch = true;
for (;;) {
const next = it.next();
if (next.done) {
return allMatch;
/**
* Searches for the value in `iterable`.
*
* @typeParam T Iterated elements type.
* @typeParam R 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;
}
if (!(allMatch = !!test(next.value))) {
return false;
}
}
return;
});
return find;
}

@@ -474,5 +423,7 @@

function itsFirst(iterable) {
if (isPushIterable(iterable)) {
return pushedFirst(iterable);
}
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedFirst(forNext) : rawFirst(it);
return isPushIterable(it) ? pushedFirst(it) : rawFirst(it);
}

@@ -482,5 +433,5 @@ /**

*/
function pushedFirst(forNext) {
function pushedFirst(it) {
let first;
forNext(element => {
pushIterated(it, element => {
first = element;

@@ -500,2 +451,53 @@ return false;

/**
* @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

@@ -505,6 +507,96 @@ * @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 A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @typeParam R A type of reduced value.

@@ -519,27 +611,6 @@ * @param iterable An iterable to reduce values of.

function itsReduction(iterable, reducer, initialValue) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedReduction(forNext, reducer, initialValue) : rawReduction(it, reducer, initialValue);
}
/**
* @internal
*/
function pushedReduction(forNext, reducer, reduced) {
forNext(element => {
reduced = reducer(reduced, element);
});
let reduced = initialValue;
itsIterated(iterable, element => { reduced = reducer(reduced, element); });
return reduced;
}
/**
* @internal
*/
function rawReduction(it, reducer, reduced) {
for (;;) {
const next = it.next();
if (next.done) {
return reduced;
}
reduced = reducer(reduced, next.value);
}
}

@@ -553,3 +624,3 @@ /**

*
* @typeParam T A type of `iterable` elements.
* @typeParam T Iterated elements type.
* @param iterable An iterable to test elements of.

@@ -563,28 +634,237 @@ * @param test A predicate function to test each element. Returns `false` to continue tests, or `true` to stop it

function itsSome(iterable, test) {
const it = iteratorOf(iterable);
const forNext = it.forNext;
return forNext ? pushedSome(forNext, test) : rawSome(it, 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 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)
: makePushIterable(iterateOverRawIterable(iterable));
}
/**
* @internal
*/
function pushedSome(forNext, test) {
let someMatches = false;
forNext(element => !(someMatches = !!test(element)));
return someMatches;
function iterateOverRawIterable(iterable) {
return accept => {
const it = iteratorOf(iterable);
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 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 rawSome(it, test) {
let someMatches = false;
for (;;) {
const next = it.next();
if (next.done) {
return someMatches;
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 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();
}
if ((someMatches = !!test(next.value))) {
return true;
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,
};
};
}

@@ -615,34 +895,59 @@

function filterArray(array, test) {
if (!array.length) {
return overNone();
}
return {
[Symbol.iterator]() {
let i = 0;
return {
[Symbol.iterator]: PushIterator$iterator,
next() {
for (;;) {
if (i >= array.length) {
return { done: true };
}
const value = array[i++];
if (test(value)) {
return { value };
}
return makePushIterable(iterateOverFilteredArray(array, test));
}
/**
* @internal
*/
function iterateOverFilteredArray(array, test) {
return accept => {
let i = 0;
const forNext = (accept) => {
for (;;) {
if (i >= array.length) {
return false;
}
const value = array[i++];
if (test(value)) {
const status = accept(value);
if (typeof status === 'boolean') {
return status;
}
},
forNext(accept) {
for (;;) {
if (i >= array.length) {
return false;
}
const value = array[i++];
if (test(value) && accept(value) === false) {
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 = () => {
for (;;) {
if (i >= array.length) {
over = true;
iterate = PushIterator$dontIterate;
next = PushIterator$noNext;
return { done: true };
}
const value = array[i++];
if (test(value)) {
return { value };
}
}
};
return {
[Symbol.iterator]: PushIterator$iterator,
[PushIterator__symbol](accept) {
iterate(accept);
return this;
},
next: () => next(),
isOver: () => over,
};
};

@@ -656,9 +961,6 @@ }

function filterIt(source, test) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? filterPusher(forNext, test) : filterRawPusher(it, test));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? filterPusher(source, test) : filterRawPusher(source, test);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -668,4 +970,13 @@ /**

*/
function filterPusher(forNext, test) {
return accept => forNext(element => !test(element) || accept(element));
function filterPusher(source, test) {
return accept => {
const tail = pushHead(source, element => {
if (test(element)) {
return accept(element);
}
return;
});
source = tail;
return !tail.isOver();
};
}

@@ -675,3 +986,7 @@ /**

*/
function filterRawPusher(it, test) {
function filterRawPusher(source, test) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return filterPusher(it, test);
}
return accept => {

@@ -684,4 +999,7 @@ for (;;) {

const value = next.value;
if (test(value) && accept(value) === false) {
return true;
if (test(value)) {
const status = accept(value);
if (typeof status === 'boolean') {
return status;
}
}

@@ -702,6 +1020,3 @@ }

function flatMapArray(array, convert = flatMapIt$defaultConverter) {
const length = array.length;
return length > 1
? { [Symbol.iterator]: () => makePushIterator(flatMapArrayPusher(array, convert)) }
: (length ? overIterable(convert(array[0])) : overNone());
return makePushIterable(iterateOverFlattenedArray(array, convert));
}

@@ -711,19 +1026,31 @@ /**

*/
function flatMapArrayPusher(array, convert) {
let cIt = itsIterator(convert(array[0]));
let index = 1;
function iterateOverFlattenedArray(array, convert) {
return accept => {
for (;;) {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!cIt.forNext(element => goOn = accept(element))) {
if (index >= array.length) {
return false;
let i = 0;
let subs;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
if (!subs) {
subs = convert(array[i]);
}
for (;;) {
let status;
const subsTail = itsHead(subs, element => status = accept(element));
if (subsTail.isOver()) {
if (++i >= array.length) {
return false;
}
subs = convert(array[i]);
}
cIt = itsIterator(convert(array[index++]));
else {
subs = subsTail;
}
if (typeof status === 'boolean') {
return status;
}
}
if (goOn === false) {
return true;
}
}
};
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
};

@@ -737,9 +1064,6 @@ }

function flatMapIt(source, convert = flatMapIt$defaultConverter) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? flatMapPusher(forNext, convert) : flatMapRawPusher(it, convert));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? flatMapPusher(source, convert) : flatMapRawPusher(source, convert);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -749,13 +1073,15 @@ /**

*/
function flatMapPusher(forNext, convert) {
let forNextSub;
function flatMapPusher(source, convert) {
let subs;
let lastSrc = false;
return accept => {
for (;;) {
while (!forNextSub) {
if (!forNext(src => {
forNextSub = itsIterator(convert(src)).forNext;
return false;
})) {
if (!forNextSub) {
while (!subs) {
const sourceTail = pushHead(source, src => {
subs = convert(src);
return true;
});
source = sourceTail;
if (sourceTail.isOver()) {
if (!subs) {
return false;

@@ -767,5 +1093,6 @@ }

// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNextSub(element => goOn = accept(element))) {
forNextSub = undefined;
let status;
const subsTail = itsHead(subs, element => status = accept(element));
if (subsTail.isOver()) {
subs = undefined;
if (lastSrc) {

@@ -775,5 +1102,8 @@ return false;

}
if (goOn === false) {
return true;
else {
subs = subsTail;
}
if (typeof status === 'boolean') {
return status;
}
}

@@ -785,7 +1115,11 @@ };

*/
function flatMapRawPusher(it, convert) {
let forNextSub;
function flatMapRawPusher(source, convert) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return flatMapPusher(it, convert);
}
let subs;
return accept => {
for (;;) {
if (!forNextSub) {
if (!subs) {
const next = it.next();

@@ -795,12 +1129,11 @@ if (next.done) {

}
forNextSub = itsIterator(convert(next.value)).forNext;
subs = convert(next.value);
}
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
let goOn;
if (!forNextSub(element => goOn = accept(element))) {
forNextSub = undefined;
let status;
const subsTail = itsHead(subs, element => status = accept(element));
subs = subsTail.isOver() ? undefined : subsTail;
if (typeof status === 'boolean') {
return status;
}
if (goOn === false) {
return true;
}
}

@@ -826,28 +1159,54 @@ };

function mapArray(array, convert) {
const length = array.length;
if (length <= 1) {
return length ? overOne(convert(array[0])) : overNone();
}
return {
[Symbol.iterator]() {
let i = 0;
return {
[Symbol.iterator]: PushIterator$iterator,
next: () => i < array.length ? { value: convert(array[i++]) } : { done: true },
forNext(accept) {
if (i >= array.length) {
return false;
}
for (;;) {
const goOn = accept(convert(array[i++]));
if (i >= array.length) {
return false;
}
if (goOn === false) {
return true;
}
}
},
};
},
return makePushIterable(iterateOverMappedArray(array, convert));
}
/**
* @internal
*/
function iterateOverMappedArray(array, convert) {
return accept => {
let i = 0;
const forNext = (accept) => {
if (i >= array.length) {
return false;
}
for (;;) {
const status = accept(convert(array[i++]));
if (i >= array.length) {
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 < array.length) {
return { value: convert(array[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,
};
};

@@ -873,9 +1232,6 @@ }

function mapIt(source, convert) {
return {
[Symbol.iterator]() {
const it = iteratorOf(source);
const forNext = it.forNext;
return makePushIterator(forNext ? mapPusher(forNext, convert) : mapRawPusher(it, convert));
},
};
return makePushIterable(accept => {
const forNext = isPushIterable(source) ? mapPusher(source, convert) : mapRawPusher(source, convert);
return accept && !forNext(accept) ? overNone() : makePushIterator(forNext);
});
}

@@ -885,4 +1241,8 @@ /**

*/
function mapPusher(forNext, convert) {
return accept => forNext(element => accept(convert(element)));
function mapPusher(source, convert) {
return accept => {
const tail = pushHead(source, element => accept(convert(element)));
source = tail;
return !tail.isOver();
};
}

@@ -892,3 +1252,7 @@ /**

*/
function mapRawPusher(it, convert) {
function mapRawPusher(source, convert) {
const it = iteratorOf(source);
if (isPushIterable(it)) {
return mapPusher(it, convert);
}
return accept => {

@@ -900,4 +1264,5 @@ for (;;) {

}
if (accept(convert(next.value)) === false) {
return true;
const status = accept(convert(next.value));
if (typeof status === 'boolean') {
return status;
}

@@ -923,3 +1288,3 @@ }

export { filterArray, filterIt, flatMapArray, flatMapIt, iteratorOf, itsEach, itsElements, itsEmpty, itsEvery, itsFirst, itsIterator, itsReduction, itsSome, makePushIterator, mapArray, mapIt, overArray, overElementsOf, overEntries, overIterable, overKeys, overMany, overNone, overOne, reverseArray };
export { PushIterator__symbol, filterArray, filterIt, flatMapArray, flatMapIt, isPushIterable, iteratorOf, itsEach, itsElements, itsEmpty, itsEvery, itsFind, itsFirst, itsHead, itsIterated, itsIterator, itsMatch, itsReduction, itsSome, makePushIterable, makePushIterator, mapArray, mapIt, overArray, overElementsOf, overEntries, overIterable, overKeys, overMany, overNone, overOne, pushHead, pushIterated, reverseArray };
//# sourceMappingURL=push-iterator.mjs.map
{
"name": "@proc7ts/push-iterator",
"version": "1.1.0",
"version": "2.0.0",
"description": "Push iteration protocol",

@@ -49,14 +49,14 @@ "keywords": [

"@types/node": "^12.12.62",
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"benchmark": "^2.1.4",
"chalk": "^4.1.0",
"codecov": "^3.7.2",
"codecov": "^3.8.0",
"eslint": "^7.10.0",
"eslint-plugin-jest": "^24.0.2",
"eslint-plugin-jest": "^24.1.0",
"gh-pages": "^3.1.0",
"jest": "^26.4.2",
"jest": "^26.5.2",
"jest-junit": "^12.0.0",
"rollup": "^2.28.2",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup": "^2.29.0",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.27.3",

@@ -66,3 +66,3 @@ "run-z": "~1.3.0",

"ts-jest": "^26.4.1",
"tslib": "^2.0.1",
"tslib": "^2.0.2",
"typedoc": "^0.19.0",

@@ -69,0 +69,0 @@ "typedoc-plugin-external-module-name": "^4.0.3",

+119
-53

@@ -8,12 +8,33 @@ Push Iteration Protocol

[![GitHub Project][github-image]][github-url]
[![API Documentation][api-docs-image]][api-docs-url]
[![API Documentation][api-docs-img]][API documentation]
Push iteration protocol is a faster alternative to traditional JavaScript [iteration protocol].
It extends [Iterator] interface with `forNext(accept: (this: void, element: T) => void | boolean): boolean` method.
The latter pushes iterated elements to `accept` function until there is no more elements, or `accept` function returns
`false` yo stop iteration. The `forNext()` method returns `true` if there are more elements to iterate, or `false`
otherwise. The former is possible only when iteration stopped, i.e. `accept` returned `false`.
It extends [Iterator] interface with special method `[PushIterator__symbol](accept?)`, where `PushIterator__symbol`
is a special symbol. This method pushes iterated elements to `accept` callback, until there is no more elements,
or `accept` function returns `true` (to suspend iteration) or `false` (to stop it).
The method returns a push iterator instance to continue iteration with. If `accept` returned `false` then further
iteration won't be possible with returned iterator.
When called without `accept` parameter it just returns an iterator.
Another method it extends [Iterator] with is `isOver()`, that checks whether iteration is over.
[iteration protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
[Iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
[npm-image]: https://img.shields.io/npm/v/@proc7ts/push-iterator.svg?logo=npm
[npm-url]: https://www.npmjs.com/package/@proc7ts/push-iterator
[build-status-img]: https://github.com/proc7ts/push-iterator/workflows/Build/badge.svg
[build-status-link]: https://github.com/proc7ts/push-iterator/actions?query=workflow%3ABuild
[codecov-image]: https://codecov.io/gh/proc7ts/push-iterator/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/proc7ts/push-iterator
[github-image]: https://img.shields.io/static/v1?logo=github&label=GitHub&message=project&color=informational
[github-url]: https://github.com/proc7ts/push-iterator
[api-docs-image]: https://img.shields.io/static/v1?logo=typescript&label=API&message=docs&color=informational
[API documentation]: https://proc7ts.github.io/push-iterator/
[IoC]: https://en.wikipedia.org/wiki/Inversion_of_control
Rationale

@@ -33,3 +54,5 @@ ---------

[benchmarking results]: https://github.com/proc7ts/push-iterator/tree/master/benchmarks
Design Goals

@@ -53,25 +76,18 @@ ------------

[iteration protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
[Iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
[Iterable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol
[benchmarking results]: https://github.com/proc7ts/push-iterator/tree/master/benchmarks
[npm-image]: https://img.shields.io/npm/v/@proc7ts/push-iterator.svg?logo=npm
[npm-url]: https://www.npmjs.com/package/@proc7ts/push-iterator
[build-status-img]: https://github.com/proc7ts/push-iterator/workflows/Build/badge.svg
[build-status-link]: https://github.com/proc7ts/push-iterator/actions?query=workflow%3ABuild
[codecov-image]: https://codecov.io/gh/proc7ts/push-iterator/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/proc7ts/push-iterator
[github-image]: https://img.shields.io/static/v1?logo=github&label=GitHub&message=project&color=informational
[github-url]: https://github.com/proc7ts/push-iterator
[api-docs-image]: https://img.shields.io/static/v1?logo=typescript&label=API&message=docs&color=informational
[api-docs-url]: https://proc7ts.github.io/push-iterator/
[IoC]: https://en.wikipedia.org/wiki/Inversion_of_control
Instant Iteration
-----------------
It is quite common to just iterate over [Iterable] instantly rather constructing its [Iterator]. The library supports
this. For that, a `[PushIterator__symbol]` method may be defined for [Iterable] in addition to `[Symbol.iterator]` one.
When the library function encounters such method, it calls it to iterate over elements instead of constructing a new
iterator.
API
---
See the full [API Documentation].
See the full [API documentation].

@@ -83,11 +99,21 @@

- `overArray(array)` - Creates a push iterable over elements of array-like structure.
- `overElementsOf(...iterables)` - Creates a push iterable over elements of other iterables.
- `overEntries(object)` - Creates a push iterable over the property key/value entries of the given object.
- `overKeys(object)` - Creates a push iterable over keys of the given object.
- `overMany(...values)` - Creates a push iterable over many values.
- `overNone()` - Returns a push iterable iterator without elements.
- `reverseArray(array)` - Creates a push iterable over elements of array-like structure in reverse order.
- [`overArray(array)`][overArray] - Creates a push iterable over elements of array-like structure.
- [`overElementsOf(...iterables)`][overElementsOf] - Creates a push iterable over elements of other iterables.
- [`overEntries(object)`][overEntries] - Creates a push iterable over the property key/value entries of the given
object.
- [`overKeys(object)`][overKeys] - Creates a push iterable over keys of the given object.
- [`overMany(...values)`[overMany] - Creates a push iterable over many values.
- [`overNone()`][overNone] - Returns a push iterable iterator without elements.
- [`reverseArray(array)`][reverseArray] - Creates a push iterable over elements of array-like structure in reverse
order.
[overArray]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overArray
[overElementsOf]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overElementsOf
[overEntries]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overEntries
[overKeys]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overKeys
[overMany]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overMany
[overNone]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#overNone
[reverseArray]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#reverseArray
### Iterable Consumption

@@ -97,16 +123,36 @@

- `itsEach(iterable, action)` - Performs the given `action` for each element of the given `iterable`.
- `itsElements(iterable[, convert])` - Creates a new, shallow-copied array instance containing elements of the source
iterable optionally converted by the given converter function. This is an `Array.from()` function analog optimized
for push iterables.
- `itsEmpty(iterable): boolean` - Checks whether the given `iterable` is empty.
- `itsEvery(iterable, test): boolean` - Tests whether all elements of the given `iterable` pass the test implemented
- [`itsEach(iterable, action)`][itsEach] - Performs the given `action` for each element of the given `iterable`.
- [`itsElements(iterable[, convert])`][itsElements] - Creates a new, shallow-copied array instance containing elements
of the source iterable optionally converted by the given converter function. This is an `Array.from()` function
analog optimized for push iterables.
- [`itsEmpty(iterable): boolean`][itsEmpty] - Checks whether the given `iterable` is empty.
- [`itsEvery(iterable, test): boolean`] - Tests whether all elements of the given `iterable` pass the test implemented
by the provided function.
- `itsFirst(iterable): T | undefined` - Extracts the first element of the given `iterable`, if any.
- `itsReduction(iterable, reducer, initialValue): T` - Applies a function against an accumulator and each element
of the given `iterable` to reduce elements to a single value.
- `itsSome(iterable, test): boolean` - Tests whether at least one element of the given `iterable` passes the test
implemented by the provided function.
- [`itsFind(iterable, search): R | undefined`][itsFind] - Searches for the value in `iterable`.
- [`itsFirst(iterable): T | undefined`][itsFirst] - Extracts the first element of the given `iterable`, if any.
- [`itsHead(iterable, accept): PushIterator`][itsHead] - Iterates over the head elements of the given iterable and
returns its tail iterator.
- [`itsIterated(iterable, accept): boolean`][itsIterated] - Iterates over elements of the given `iterable`.
- [`itsIterator(iterable)`][itsIterator] - Starts iteration over the given `iterable`. Always returns a push iterator.
- [`itsMatch(iterable, test): T | undefined`][itsMatch] - Extracts the first element matching the given condition from
`iterable`.
- [`itsReduction(iterable, reducer, initialValue): T`][itsReduction] - Applies a function against an accumulator and
each element of the given `iterable` to reduce elements to a single value.
- [`itsSome(iterable, test): boolean`][itsSome] - Tests whether at least one element of the given `iterable` passes the
test implemented by the provided function.
[itsEach]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsEach
[itsElements]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsElements
[itsEmpty]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsEmpty
[itsEvery]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsEvery
[itsFind]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsFind
[itsFirst]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsFirst
[itsHead]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsHead
[itsIterated]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsIterated
[itsIterator]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsIterator
[itsMatch]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsMatch
[itsReduction]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsReduction
[itsSome]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#itsSome
### Iterable Transformation

@@ -116,8 +162,12 @@

- `filterIt(source, test)` - Creates a push iterable with all `source` iterable elements that pass the test
- [`filterIt(source, test)`][filterIt] - Creates a push iterable with all `source` iterable elements that pass the test
implemented by provided function.
- `flatMapIt(source, convert?)` - First maps each element of the `source` iterable using a mapping function,
then flattens the result into new push iterable.
- `mapIt(source, convert)` - Creates a push iterable with the results of calling a provided function on every element
of the `source` iterable.
- [`flatMapIt(source, convert?)`][flatMapIt] - First maps each element of the `source` iterable using a mapping
function, then flattens the result into new push iterable.
- [`mapIt(source, convert)`][mapIt] - Creates a push iterable with the results of calling a provided function on every
element of the `source` iterable.
[filterIt]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#filterIt
[flatMapIt]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#flatMapIt
[mapIt]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#mapIt

@@ -129,14 +179,30 @@

- `filterArray(aray, test)` - Creates a push iterable with all `array` elements that pass the test implemented
by provided function.
- `flatMapArray(array, convert?)` - First maps each element of the source `array` using a mapping function,
then flattens the result into new push iterable.
- `mapArray(array, convert)` - Creates a push iterable with the results of calling a provided function on every element
of the given `array`.
- [`filterArray(aray, test)`][filterArray] - Creates a push iterable with all `array` elements that pass the test
implemented by provided function.
- [`flatMapArray(array, convert?)`][flatMapArray] - First maps each element of the source `array` using a mapping
function, then flattens the result into new push iterable.
- [`mapArray(array, convert)`][mapArray] - Creates a push iterable with the results of calling a provided function on
every element of the given `array`.
[filterArray]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#filterArray
[flatMapArray]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#flatMapArray
[mapArray]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#mapArray
### Utilities
- `iteratorOf(iterable)` - Constructs iterator over elements of the given `iterable`.
- `itsIterator(iterable)` - Starts iteration over the given `iterable`. Always returns a push iterator.
- `makePushIterator(forNext)` - Creates push iterator implementation.
- [`isPushIterable(iterable)`][isPushIterable] - Checks whether the given iterable or iterator conforms to push
iteration protocol.
- [`iteratorOf(iterable)`][iteratorOf] - Constructs iterator over elements of the given `iterable`.
- [`makePushIterable(iterate)`][makePushIterable] - Creates a push iterable implementation.
- [`makePushIterator(forNext)`][makePushIterator] - Creates a push iterator implementation.
- [`pushHead(iterable, accept): PushIterator`][pushHead] - Iterates over the head elements of the given push iterable
and returns its tail iterator.
- [`pushIterated(iterable, accept): boolean`][pushIterated] - Iterates over elements of the given push iterable.
[isPushIterable]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#isPushIterable
[iteratorOf]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#iteratorOf
[makePushIterable]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#makePushIterable
[makePushIterator]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#makePushIterator
[pushHead]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#pushHead
[pushIterated]: https://proc7ts.github.io/push-iterator/modules/@proc7ts_push-iterator.html#pushIterated
import type { PushIterator } from '../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.
*/
export declare function itsIterator<T>(iterable: Iterable<T>): PushIterator<T>;
//# sourceMappingURL=its-iterator.d.ts.map
{"version":3,"file":"its-iterator.d.ts","sourceRoot":"","sources":["../../src/base/its-iterator.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAKrE"}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display