functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
29 lines (28 loc) • 796 B
TypeScript
/**
* A generic function type.
*/
export type Func<I, O> = (_: I) => O;
/**
* A postfix compose function.
*/
export declare const compose: <I, X>(g: Func<I, X>) => <O>(f: Func<X, O>) => Func<I, O>;
/**
* A generic identity function.
*/
export declare const identity: <T>(value: T) => T;
/**
* Flips the arguments of a curried function.
*/
export declare const flip: <A, B, C>(f: (a: A) => (b: B) => C) => (b: B) => (a: A) => C;
/**
* A functional utility type that enables seamless chaining of transformations.
*/
type Fn<I, O> = {
readonly result: Func<I, O>;
readonly then: <T>(g: Func<O, T>) => Fn<I, T>;
};
/**
* Creates an `Fn` instance from a function, enabling chaining of transformations.
*/
export declare const fn: <I, O>(result: Func<I, O>) => Fn<I, O>;
export {};