@jhel/iterup
Version:
A TypeScript iterator utility library that provides lazy evaluation for efficient data processing
80 lines (79 loc) • 2.61 kB
TypeScript
/**
* Utility functions for type checking and working with iterators.
*
* This module provides helper functions to determine the type of iterators
* and check for specific iterator interfaces at runtime.
*/
import { BaseAsyncIterator, BaseSyncIterator, None, type Iterup } from "./core";
/**
* Type guard to check if a value is a synchronous iterator.
* Checks for the presence of the Symbol.iterator method.
*
* @template Value - The type of values the iterator should yield
* @param value - The value to check
* @returns True if the value is a synchronous iterator
*
* @example
* ```ts
* if (isIterator(someValue)) {
* // someValue is now typed as BaseSyncIterator<Value>
* for (const item of someValue) {
* console.log(item);
* }
* }
* ```
*/
export declare function isIterator<Value>(value: unknown): value is BaseSyncIterator<Value>;
/**
* Type guard to check if a value is iterable (has Symbol.iterator).
* This includes iterables like arrays, sets, maps, and strings.
*
* @template Value - The type of values the iterable should yield
* @param value - The value to check
* @returns True if the value is iterable
*
* @example
* ```ts
* if (isIterable(someValue)) {
* for (const item of someValue) {
* console.log(item);
* }
* }
* ```
*/
export declare function isIterable<Value>(value: unknown): value is Iterable<Value>;
/**
* Type guard to check if a value is an asynchronous iterator.
* Checks for the presence of the Symbol.asyncIterator method.
*
* @template Value - The type of values the iterator should yield
* @param value - The value to check
* @returns True if the value is an asynchronous iterator
*
* @example
* ```ts
* if (isAsyncIterator(someValue)) {
* for await (const item of someValue) {
* console.log(item);
* }
* }
* ```
*/
export declare function isAsyncIterator<Value>(value: unknown): value is BaseAsyncIterator<Value>;
/**
* Type guard to check if an async iterator is an Iterup instance.
* Checks for the presence of the IterupID symbol that marks enhanced iterators.
*
* @template Value - The type of values the iterator yields
* @param value - The async iterator to check
* @returns True if the iterator is an Iterup instance with extension methods
*
* @example
* ```ts
* if (isIterup(someAsyncIterator)) {
* const result = await someAsyncIterator.map(x => x * 2).collect();
* }
* ```
*/
export declare function isIterup<Value>(value: BaseAsyncIterator<Value>): value is Iterup<Value>;
export declare function unwrapResult<Value>(result: IteratorResult<Value>): Value | typeof None;