@synstack/pipe
Version:
Simple typesafe pipe utility for Functional Programming
30 lines (28 loc) • 1.01 kB
TypeScript
type PipeFn<V, R> = (value: V) => R;
declare abstract class Pipeable<TInstance = any, TValue = any> {
_<R extends Pipeable>(fn: PipeFn<TInstance, R>): R;
_<R extends Promise<any>>(fn: PipeFn<TInstance, R>): R;
_<R>(fn: PipeFn<TInstance, R>): Pipe<R>;
_$<R extends Pipeable<any, any>>(fn: PipeFn<TValue, R>): R;
_$<R extends Promise<any>>(fn: PipeFn<TValue, R>): R;
_$<R>(fn: PipeFn<TValue, R>): Pipe<R>;
get $(): TValue;
abstract instanceOf(): TInstance;
abstract valueOf(): TValue;
}
declare class Pipe<V> extends Pipeable<V, V> {
private readonly value;
constructor(value: V);
static from<V>(value: V): Pipe<V>;
valueOf(): V;
instanceOf(): V;
}
/**
* Create a new pipe
* @param value the initial value
* @returns a pipe instance with the initial value
*/
declare function pipe<V extends Pipeable>(value: V): V;
declare function pipe<V extends Promise<any>>(value: V): V;
declare function pipe<V>(value: V): Pipe<V>;
export { Pipe, Pipeable, pipe };