neverthrow
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -226,2 +226,5 @@ 'use strict'; | ||
}; | ||
ResultAsync.prototype.unwrapOr = function (t) { | ||
return this._promise.then(function (res) { return res.unwrapOr(t); }); | ||
}; | ||
// Makes ResultAsync awaitable | ||
@@ -228,0 +231,0 @@ ResultAsync.prototype.then = function (successCallback) { |
@@ -43,2 +43,3 @@ declare type Result<T, E> = Ok<T, E> | Err<T, E>; | ||
match<A>(ok: (t: T) => A, _err: (e: E) => A): Promise<A>; | ||
unwrapOr(t: T): Promise<T>; | ||
then<A>(successCallback: (res: Result<T, E>) => A): Promise<A>; | ||
@@ -45,0 +46,0 @@ } |
@@ -222,2 +222,5 @@ // eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
}; | ||
ResultAsync.prototype.unwrapOr = function (t) { | ||
return this._promise.then(function (res) { return res.unwrapOr(t); }); | ||
}; | ||
// Makes ResultAsync awaitable | ||
@@ -224,0 +227,0 @@ ResultAsync.prototype.then = function (successCallback) { |
{ | ||
"name": "neverthrow", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Stop throwing errors, and instead return Results!", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -335,5 +335,3 @@ # NeverThrow 🙅 | ||
const unwrapped: number = myResult | ||
.map(multiply) | ||
.unwrapOr(10) | ||
const unwrapped: number = myResult.map(multiply).unwrapOr(10) | ||
``` | ||
@@ -656,2 +654,22 @@ | ||
### `ResultAsync.unwrapOr` (method) | ||
Unwrap the `Ok` value, or return the default if there is an `Err`. | ||
Works just like `Result.unwrapOr` but returns a `Promise<T>` instead of `T`. | ||
**Signature:** | ||
```typescript | ||
unwrapOr<T>(v: T): Promise<T> { ... } | ||
``` | ||
**Example**: | ||
```typescript | ||
const unwrapped: number = await errAsync(0).unwrapOr(10) | ||
// unwrapped = 10 | ||
``` | ||
--- | ||
### `ResultAsync.andThen` (method) | ||
@@ -658,0 +676,0 @@ |
64097
789
933