@dancrumb/fpish
Version:
FP-friendly classes for Typescript
36 lines (35 loc) • 1.24 kB
TypeScript
/**
* This is a simple function that takes data of one type and returns data of another type
*/
type Builder<T, I = void> = (input: I) => T | Promise<T>;
/**
* Represents a value that is initialized in a lazy manner, i.e. not until it is needed
*/
export declare class Lazy<T> {
private builder;
private value;
private constructor();
/**
* Create a Lazy<T> by providing the function that will be called when the value
* is first needed
*
* @param builder - the initializing function. Since this could be doing anything, it can have
* side effects
*/
static create<NT>(builder: Builder<NT>): Lazy<NT>;
/**
* Gets the value of the lazy object, initializing it, if necessary
*/
getValue(): Promise<T>;
/**
* Creates a new `Lazy<S>` value. The initializer takes the value of this `Lazy<T>` and uses it
* to create a `Lazy<S>`
*
* Multiple values can be chained; they won't initialize until the last one is resolved.
*
* @param builder - the initializing function. Since this could be doing anything, it can have
* side effects
*/
chain<S>(builder: Builder<S, T>): Lazy<S>;
}
export {};