import { type PrimativeKey, type ReadKeyFunction } from '../key'; import { type DecisionFunction } from '../value/decision'; import { type Maybe } from '../value/maybe.type'; /** * An Iterable or a value. * * Note that strings are a valid Iterable, allowing iteration over characters. */ export type IterableOrValue = T | Iterable; /** * Converts an IterableOrValue to an Iterable. Non-iterable values are wrapped in an array. * * @param values - The value or iterable to convert. * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false) * @returns An Iterable containing the value(s) */ export declare function asIterable(values: IterableOrValue, treatStringAsIterable?: boolean): Iterable; /** * Converts an IterableOrValue to an array. * * By default treats strings as a non-iterable value, using the string as a single value. * * @param values - The value or iterable to convert. * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false) * @returns An array containing the value(s) * * @dbxUtil * @dbxUtilCategory iterable * @dbxUtilTags iterable, array, convert, normalize, ensure * @dbxUtilRelated iterable-to-set, iterable-to-map, as-iterable */ export declare function iterableToArray(values: IterableOrValue, treatStringAsIterable?: boolean): T[]; /** * Converts an IterableOrValue to a Set. * * By default treats strings as a non-iterable value, using the string as a single value. * * @param values - The value or iterable to convert. * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false) * @returns Deduped membership view collected from `values`. * * @dbxUtil * @dbxUtilCategory iterable * @dbxUtilTags iterable, set, convert, normalize, unique, dedupe * @dbxUtilRelated iterable-to-array, iterable-to-map */ export declare function iterableToSet(values: IterableOrValue, treatStringAsIterable?: boolean): Set; /** * Converts an IterableOrValue to a Map using a key extraction function. * * @param values - The value or iterable to convert. * @param readKey - Function to extract the key from each value. * @returns Lookup keyed by `readKey` results; the last entry per key wins. */ export declare function iterableToMap(values: IterableOrValue, readKey: ReadKeyFunction): Map, T>; /** * Type guard that returns true if the input is an Iterable. * By default, strings are not treated as iterable. * * @param values - The value to check. * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false) * @returns True if the value is iterable. * * @dbxUtil * @dbxUtilCategory iterable * @dbxUtilTags iterable, type-guard, check, symbol-iterator * @dbxUtilRelated is-empty-iterable, as-iterable */ export declare function isIterable(values: unknown, treatStringAsIterable?: boolean): values is Iterable; /** * Returns true if the iterable has no values. * * @param values - The iterable to check. * @returns True if the iterable is empty. * * @dbxUtil * @dbxUtilCategory iterable * @dbxUtilTags iterable, empty, check, length * @dbxUtilRelated is-iterable, first-value-from-iterable */ export declare function isEmptyIterable(values: Iterable): boolean; /** * Returns the first value from the Iterable, or undefined if empty. Order is not guaranteed. * * @param values - The iterable to read from. * @returns The first value, or undefined if empty. */ export declare function firstValueFromIterable(values: Iterable): Maybe; /** * Takes up to `count` items from the iterable. Order is not guaranteed. * * @param values - Source iterable feeding the take operation. * @param count - Upper bound on items to consume from the iterator. * @returns Consumed items, capped at `count`. */ export declare function takeValuesFromIterable(values: Iterable, count: number): T[]; /** * Iterates over iterable values, calling the function for each one. * * @param values - The iterable to iterate over. * @param fn - The function to call for each value. */ export declare function forEachInIterable(values: Iterable, fn: (value: T) => void): void; /** * Calls the function for each value if the input is iterable, or once with the value if it's a single value. * Does nothing if the input is null/undefined. * * @param values - The value or iterable to process. * @param fn - The function to call for each value. * @param treatStringAsIterable - Whether to treat strings as iterable (defaults to false) */ export declare function useIterableOrValue(values: Maybe>, fn: (value: T) => void, treatStringAsIterable?: boolean): void; /** * Finds and returns the first value in the iterable that matches the decision function. * * @param values - The iterable to search. * @param fn - Decision function that returns true for the desired value. * @returns The first matching value, or undefined. */ export declare function findInIterable(values: Iterable, fn: DecisionFunction): Maybe; /** * Returns true if any value in the iterable matches the decision function. * * @param values - The iterable to search. * @param fn - Decision function to test each value. * @returns True if at least one value matches. */ export declare function existsInIterable(values: Iterable, fn: DecisionFunction): boolean; /** * Filters values from the iterable, keeping those that pass the decision function. * * @param values - Source iterable feeding the filter. * @param fn - Predicate that decides whether each value flows through. * @returns Items for which the predicate returned true, in iteration order. */ export declare function filterFromIterable(values: Iterable, fn: DecisionFunction): T[]; /** * Wraps a single tuple value into an array. Distinguishes between a single tuple and an array of tuples * by checking whether nested array elements have uniform length. * * Used to prevent functions from incorrectly treating a tuple as an array of values. * * @param input - The tuple or array of tuples to wrap. * @returns An array containing the tuple(s) * @throws {Error} If input is not an array. */ export declare function wrapTuples(input: IterableOrValue): T[];