/** * Functions to test (as typeguards) and coerce generators, iterators, etc. * * @module functions */ import type { Async, Sync, Genable, FullIterable, FullIterableIterator } from "./types"; /** * Predicate/Type Guard for any function. * @param f */ export declare const isFunction: (f: any) => f is A; /** * Predicate/type guard to determine if an object is [[Genable]]. An object is [[Genable]] if it * supports the `Iterator` or `Iterable` protocols. (Generators support both). * @param g */ export declare const isGenable: (g: any) => g is Iterator | Iterable | Generator | import("./enhancements").Enhancements; export declare const isAsyncGenable: (g: any) => g is AsyncIterator | AsyncIterable | AsyncGenerator | Generator | Iterator | Iterable | import("./enhancements").Enhancements | import("./enhancements").Enhancements; /** * Predicate/type guard to determine if an object is (or looks like, structurally) a Generator. * @param g */ export declare const isGenerator: (g: any) => g is Generator; /** * Predicate/type guard to determine if an object is (or looks like, structurally) a AsyncGenerator. * @param g */ export declare const isAsyncGenerator: (g: any) => g is AsyncGenerator; /** * Coerce an object to an object that can act as a generator (that is, satisfy both `Iterator` * and `Iterable`). * * If it is an `Iterator` but not `Iterable`, or `Iterable` but not `Iterator`, it is wrapped * in a generator. This generator is __not__ enhanced. Use [[Sync.enhance]] on the result if * you need an enhanced generator. * @param i */ export declare function toGenerator(i: Genable): Generator; /** * Coerce an object to an object that can act as a async generator (that is, satisfy both `Iterator` * and `Iterable`). * * If it is an `AsyncIterator` but not `AsyncIterable`, or `AsyncIterable` but not `AsyncIterator`, * it is wrapped in an async generator. This generator is __not__ enhanced. Use [[Async.enhance]] on the result if * you need an enhanced generator. * @param i */ export declare function toAsyncGenerator(i: Genable | Genable): AsyncGenerator; /** * Coerce a sync [[Genable]] object to an `Iterator`. If the object is a `Generator` or an `Iterator` it is returned, * while if it is an `Iterable`, `[Symbol.iterator]`() is invoked. * @param i */ export declare function toIterator(i: Genable): Iterator; /** * Coerce an async [[Genable]] object to an `AsyncIterator`. If the object is a `Generator` or an `Iterator` it is returned, * while if it is an `Iterable`, `[Symbol.iterator]`() is invoked. * @param i */ export declare function toAsyncIterator(i: Genable): AsyncIterator; /** * Coerce a [[Genable]] object to `Iterable`. If it is already an `Iterable`, it is returned * unchanged. If it is an `Iterator`, it is wrapped in an object with a `[Symbol.iterator]` * method that returns the supplied iterator. * @param i */ export declare function toIterable(i: Genable): FullIterable; /** * Coerce a [[Genable]] object to `AsyncIterable`. If it is already an `AsyncIterable`, it is returned * unchanged. If it is an `AsyncIterator`, it is wrapped in an object with a `[Symbol.asyncIterator]` * method that returns the supplied iterator. * @param i */ export declare function toAsyncIterable(i: Genable): FullIterable; /** * Similar to [[toGenerator]], but does not require the presence of `Generator.return` or `Generator.throw` methods. * @param i */ export declare function toIterableIterator(i: Genable): FullIterableIterator; /** * Similar to [[toAsyncGenerator]], but does not require the presence of `AsyncGenerator.return` or * `AsyncGenerator.throw` methods. * @param i */ export declare function toAsyncIterableIterator(i: Genable): FullIterableIterator; /** * Predicate/type guard, returns `true` if the argument satisfies the `Iterator` protocol (has a `next()` method). * * Note: There is no way to statically distinguish between an `Iterator` and an `AsyncIterator`. You will get * runtime errors if you don't anticipate the distinction. * @param i */ export declare const isIterator: (i: any) => i is Iterator; /** * Predicate/type guard, returns `true` if the argument satisfies the `AsyncIterator` protocol (has a `next()` method). * * Note: There is no way to statically distinguish between an `Iterator` and an `AsyncIterator`. You will get * runtime errors if you don't anticipate the distinction. * @param i */ export declare const isAsyncIterator: (i: any) => i is AsyncIterator; /** * Predicate/type guard, returns `true` if the argument satisfies the `Iterable` protocol (has a `[Symbol.iterator]` * method). * @param i */ export declare const isIterable: (i: any) => i is Iterable & { [Symbol.iterator]: () => Iterator; }; /** * Predicate/type guard, returns `true` if the argument satisfies the `AsyncIterable` protocol (has a `[Symbol.asyncIterator]` * method). * @param i */ export declare const isAsyncIterable: (i: any) => i is AsyncIterable & { [Symbol.asyncIterator]: () => AsyncIterator; }; /** * Predicate/type guard, returns `true` if the argument satisfies the `Iterable` protocol (has a `[Symbol.iterator]` * method) and the `Iterator` protocol (a next() method). * @param i */ export declare const isIterableIterator: (i: any) => i is IterableIterator & { [Symbol.iterator]: () => IterableIterator & any; }; /** * Predicate/type guard, returns `true` if the argument satisfies the `AsyncIterable` protocol (has a `[Symbol.asyncIterator]` * method) and the `AsyncIterator` protocol (a next() method). * @param i */ export declare const isAsyncIterableIterator: (i: any) => i is AsyncIterable & { [Symbol.asyncIterator]: () => AsyncIterable & any; }; /** * Wrap a function in a catch block. * @param f * @param onError Called when an error is thrown. The return value is returned. If not supplied, undefined is returned. */ export declare const doCatch: (f: (...args: A) => R, onError?: ((e: Error) => R) | undefined) => (...args: A) => R | undefined; //# sourceMappingURL=functions.d.ts.map