Newer
Older
ServerGenerator / src / ExampleOutput / Result.ts
/*
        TOO MUCH OVERENGINEERING
*/


export interface Ok<T> {
    isSuccessful: true;
    value: T;
}

export interface Err {
    isSuccessful: false;
    errorMessage: string;
}

export type Result<T> = Ok<T> | Err;

export const andThen = <T, R>(fn: (a: T) => Result<R>) => (result: Result<T>) => {
    if (result.isSuccessful) {
        return fn(result.value);
    }
    else {
        return result;
    }
}