doddle
Version:
Tiny yet feature-packed (async) iteration toolkit.
110 lines • 3.91 kB
TypeScript
import { type Doddle, type DoddleAsync } from "../doddle/index.js";
import { type MaybePromise } from "../utils.js";
import { ASeq } from "./aseq.class.js";
/**
* Creates a {@link ASeq} from the sequential input. See examples for usage.
*
* @category Create
* @example
* // An array
* aseq([1, 2, 3])
*
* // A generator function
* aseq(function* () {
* yield 1
* yield 2
* })
*
* // An async generator function
* aseq(async function* () {
* yield 1
* yield 2
* })
*
* // An array-like object, such as a NodeList:
* seq(document.getElementsByTagName("div"))
*
* // A readable stream
* const response = await fetch("https://example.com/data")
* aseq(response.body!)
*
* // An async function returning a sequence
* aseq(async () => [1, 2, 3])
*
* // A Doddle yielding a sequence
* aseq(doddle(() => [1, 2, 3]))
*
* // An async Doddle yielding a sequence
* aseq(doddle(async () => [1, 2, 3]))
*
* // An iterable
* aseq(seq([1, 2, 3]))
*
* // An async iterable
* aseq(aseq([1, 2, 3]))
*
* // An async function returning an async iterable
* aseq(async () => aseq([1, 2, 3]))
*
* // ⛔ Strings are not allowed here.
* seq("hello")
*
* @param input The input to create the {@link ASeq} from.
*/
export declare function aseq<E>(input: readonly E[]): ASeq<E>;
export declare function aseq<E>(input: ASeq.SimpleInput<PromiseLike<DoddleAsync<E>>>): ASeq<E>;
export declare function aseq<E>(input: ASeq.SimpleInput<DoddleAsync<E>>): ASeq<E>;
export declare function aseq<E>(input: ASeq.SimpleInput<PromiseLike<E>>): ASeq<E>;
export declare function aseq<E>(input: ASeq.SimpleInput<Doddle<E>>): ASeq<E>;
export declare function aseq<E>(input: ASeq.SimpleInput<MaybePromise<E>>): ASeq<E>;
export declare function aseq<E>(input: ASeq.Input<E>): ASeq<E>;
/**
* Tools for creating {@link ASeq} instances.
*
* @category Create
* @class
*/
export declare namespace aseq {
/**
* Creates a {@link Seq} from the own, enumerable, string key-value pairs of an object. Values
* are produced 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): ASeq<[keyof Object & string, Object[keyof Object]]>;
/**
* Creates an {@link ASeq} 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,
* possibly asynchronously.
* @returns An {@link ASeq} of the generated items.
*/
function iterate<T>(count: number, projection: ASeq.IndexIteratee<T>): ASeq<T>;
/**
* Creates an {@link ASeq} 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 An {@link ASeq} of numbers in the specified range.
*/
function range(start: number, end: number, size?: number): ASeq<number>;
/**
* Checks if the provided input is an {@link ASeq}.
*
* @param input Input to check.
* @returns `true` if the input is an {@link ASeq}, otherwise `false`.
*/
function is<T = unknown>(input: any): input is ASeq<T>;
/**
* Creates an {@link ASeq} that throws an error when iterated.
*
* @param thrower Function that returns the error to throw.
* @returns An {@link ASeq} that throws the specified error when iterated.
*/
function throws<T = never>(thrower: () => Error): ASeq<T>;
}
//# sourceMappingURL=aseq.ctor.d.ts.map