scats
Version:
Useful scala classes in typescript
43 lines (42 loc) • 2.19 kB
TypeScript
import { Option } from './option.js';
import { Mappable } from './mappable.js';
export declare function identity<T>(x: T): T;
export declare function toErrorConversion(x: unknown): Error;
export declare type StepFunction<R> = (state: any) => R;
export declare type StepCondition = (state: any) => boolean;
export interface Filterable<T, R extends Mappable<T>> {
filter(p: (x: T) => boolean): R;
}
export declare type MaybeWithFilter<C extends Mappable<any>, R> = C extends Filterable<any, Mappable<any>> ? StepWithFilter<R> : Step<R>;
export declare type TaskMaybeWithFilter<C extends Mappable<any>> = C extends Filterable<any, Mappable<any>> ? TaskWithFilter<C> : Task<C>;
export interface Step<R> {
readonly name: Option<string>;
invokeStep(state: any): R;
}
export declare type Task<C extends Mappable<any>> = Step<Promise<C>>;
export declare class StepWithFilter<R> implements Step<R> {
readonly name: Option<string>;
readonly f: StepFunction<R>;
readonly filter: Option<StepCondition>;
constructor(name: Option<string>, f: StepFunction<R>, filter: Option<StepCondition>);
if(condition: (state: any) => boolean): Step<R>;
invokeStep(state: Record<string, unknown>): R;
}
export declare class TaskWithFilter<C extends Mappable<any>> implements Task<C> {
readonly name: Option<string>;
readonly f: StepFunction<Promise<C>>;
readonly filter: Option<StepCondition>;
constructor(name: Option<string>, f: StepFunction<Promise<C>>, filter: Option<StepCondition>);
if(condition: (state: any) => boolean): Step<Promise<C>>;
invokeStep(state: Record<string, unknown>): Promise<C>;
}
export declare function step<C extends Mappable<any>>(name: string, f: StepFunction<C>): MaybeWithFilter<C, C>;
export declare function task<C extends Mappable<any>>(name: string, f: StepFunction<Promise<C>>): TaskMaybeWithFilter<C>;
export declare function forComprehension<C extends Mappable<any>>(...steps: Step<C>[]): {
yield: (final: (state: any) => any) => C;
};
export declare namespace forComprehension {
function promise<C extends Mappable<any>>(...steps: Task<C>[]): {
yield: (final: (state: any) => any) => Promise<C>;
};
}