README
ts-swift-result
Swift-like Result & AsyncResult types
Getting started
$ npm install ts-swift-result --save
Overview
Result
export declare type Result<Success, Failure> =
| {
readonly tag: 'success'
readonly success: Success
}
| {
readonly tag: 'failure'
readonly failure: Failure
}
//...
export declare const Result: {
readonly success: typeof createSuccess
readonly failure: typeof createFailure
readonly map: typeof map
readonly flatMap: typeof flatMap
readonly mapError: typeof mapError
readonly flatMapError: typeof flatMapError
readonly unwrap: typeof unwrap
readonly combine: typeof combine
}
AsyncResult
export type AsyncResult<Success, Failure> = Promise<Result<Success, Failure>>
//...
export declare const AsyncResult: {
readonly map: typeof map
readonly mapAsync: typeof mapAsync
readonly flatMap: typeof flatMap
readonly mapError: typeof mapError
readonly mapErrorAsync: typeof mapErrorAsync
readonly flatMapError: typeof flatMapError
readonly unwrap: typeof unwrap
readonly combine: typeof combine
}
Credits
- Railway oriented programming article by Scott Wlaschin