doddle
Version:
Tiny yet feature-packed (async) iteration toolkit.
92 lines • 3.23 kB
TypeScript
import { type Doddle } from "../doddle/index.js";
import { Seq } from "./seq.class.js";
/**
* Creates a {@link Seq} from the provided input. See examples for usage.
*
* @category Create
* @example
* // Array
* seq([1, 2, 3]) // {1, 2, 3}
*
* // Generator function
* seq(function* () {
* yield 1
* yield 2
* })
*
* // Doddle yielding a sequence
* seq(doddle(() => [1, 2, 3]))
*
* // Function returning a sequence
* seq(() => [1, 2, 3])
*
* // An iterable
* seq(seq([1, 2, 3]))
*
* // An array-like object, such as a NodeList:
* seq(document.getElementsByTagName("div"))
*
* // An ITERATOR, which is a special case that will be cached.
* seq(seq([1, 2, 3])[Symbol.iterator]())
*
* // ⛔ Strings are not allowed here
* seq("hello")
*
* @param input The input to create the {@link Seq} from.
*/
export declare function seq(input: readonly never[]): Seq<never>;
export declare function seq<E>(input: Seq.ObjectIterable<Doddle<E>>): Seq<E>;
export declare function seq<E>(input: readonly E[]): Seq<E>;
export declare function seq<E>(input: Seq.Input<E>): Seq<E>;
/**
* Tools for creating {@link Seq} instances.
*
* @category Create
* @example
* seq.range(0, 10) // { 0 .. 10 }
* seq.iterate(5, i => i * 2) // { 0, 2, 4, 6, 8 }
*/
export declare namespace seq {
/**
* Creates a {@link Seq} of items by iterating a projection function.
*
* @param count Number of items to iterate
* @param projection Function that receives the index and returns the item for that index.
* @returns A {@link Seq} of the generated items.
*/
function iterate<T>(count: number, projection: Seq.IndexIteratee<T>): Seq<T>;
/**
* Creates a {@link Seq} from the own, enumerable, string key-value pairs of an object, evaluated
* lazily.
*
* @template Object Type of the source object.
* @param source Source object to create the {@link Seq} from.
* @returns A {@link Seq} of key-value pairs from the source object.
*/
function fromObject<Object extends object>(source: Object): Seq<[keyof Object & string, Object[keyof Object]]>;
/**
* Creates a {@link Seq} of numbers in the specified range.
*
* @param start Starting number of the range.
* @param end Ending number of the range (exclusive).
* @param size Step size for the range. Defaults to 1.
* @returns A {@link Seq} of numbers in the specified range.
*/
function range(start: number, end: number, size?: number): Seq<number>;
/**
* Checks if the provided input is a {@link Seq}.
*
* @template T Type of items in the {@link Seq}.
* @param input Input to check.
* @returns `true` if the input is a {@link Seq}, otherwise `false`.
*/
function is<T = unknown>(input: any): input is Seq<T>;
/**
* Creates a {@link Seq} that throws an error when iterated.
*
* @param thrower Function that returns the error to throw.
* @returns A {@link Seq} that throws the specified error when iterated.
*/
function throws<T = never>(thrower: () => Error): Seq<T>;
}
//# sourceMappingURL=seq.ctor.d.ts.map