fx-flow v0.7.0 / flow / Result
Class: Result<T>
To describe a result of program.
Example
new Result({ data: 1 }).unwrapOr(2) // 1
new Result({ err: '' }).unwrapOr(2) // 2
Type parameters
• T
Constructors
new Result()
new Result<
T
>(args
):Result
<T
>
Parameters
• args: object
| object
Returns
Result
<T
>
Source
packages/core/src/flow/result.ts:19
Properties
data
private
data:undefined
|T
Source
packages/core/src/flow/result.ts:17
err
private
err:undefined
|string
Source
packages/core/src/flow/result.ts:16
ok
private
ok:boolean
Source
packages/core/src/flow/result.ts:15
Methods
error()
error():
undefined
|string
Return error message if result is failure
Returns
undefined
| string
Source
packages/core/src/flow/result.ts:56
isErr()
isErr():
boolean
Check if result is failure
Returns
boolean
Source
packages/core/src/flow/result.ts:118
isOk()
isOk():
boolean
Check if result is success
Returns
boolean
Source
packages/core/src/flow/result.ts:113
isPromise()
isPromise():
boolean
Returns
boolean
Source
packages/core/src/flow/result.ts:123
map()
map<
R
>(fn
):Result
<R
>
Return a result whose data is the result of fn
, if result is success
Type parameters
• R
Parameters
• fn
Returns
Result
<R
>
Source
packages/core/src/flow/result.ts:63
mapErr()
mapErr(
err
):Result
<T
>
Return a result with the same data of the original one if result is success or return a result with err
Parameters
• err: string
Returns
Result
<T
>
Source
packages/core/src/flow/result.ts:87
mapOr()
mapOr<
R
>(fn
,data
):Result
<R
>
Return a result whose data is the result of fn
, if result is success, or data
Type parameters
• R
Parameters
• fn
• data: R
Returns
Result
<R
>
Source
packages/core/src/flow/result.ts:71
mapOrElse()
mapOrElse<
R
>(fn
,fn2
):Result
<R
>
Return a result whose data is the result of fn
, if result is success, or the result of fn2
Type parameters
• R
Parameters
• fn
• fn2
Returns
Result
<R
>
Source
packages/core/src/flow/result.ts:79
unwrap()
unwrap():
T
Return data of result if result is success, or throw an error
Returns
T
Source
packages/core/src/flow/result.ts:32
unwrapOr()
unwrapOr(
data
):T
Return data of result if result is success, or return data
Parameters
• data: T
Returns
T
Source
packages/core/src/flow/result.ts:40
unwrapOrElse()
unwrapOrElse(
fn
):T
Return data of result if result is success, or return the result of fn
Parameters
• fn
Returns
T
Source
packages/core/src/flow/result.ts:48
wait()
Wait for data
- Result<Promise<T>> -> Promise<Result<T>>
- Result<T> -> Promise<Result<T>>