Created
May 22, 2021 05:37
-
-
Save LironHazan/d619844d94106d8020cfc73c9d025cb0 to your computer and use it in GitHub Desktop.
snippet for a blog post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ResultT<E, T> { | |
private result: Result<ErrorClassification, T>; | |
constructor(result: Result<ErrorClassification, T>) { | |
this.result = result; | |
} | |
ok(onSuccessFn: (lifted: T) => ResultT<E, T>): ResultT<E, T> { | |
return isError(this.result) ? this : onSuccessFn(this.result as T); | |
} | |
err(onFailureFn: (error: ErrorClassification) => ResultT<E, T>): ResultT<E, T> { | |
return isError(this.result) ? onFailureFn(this.result as ErrorClassification) : this; | |
} | |
map<A>(transformFn: (a: T) => A): ResultT<never, T> { | |
this.result = transformFn(this.result as T) as any; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment