Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaschultz committed Oct 24, 2024
2 parents c0243eb + 3c31d2e commit 73c78d0
Show file tree
Hide file tree
Showing 10 changed files with 3,532 additions and 16,211 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-rice-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"neverthrow": patch
---

docs: updated README.md about `safeTry` and added @deprecated tag to safeUnwrap
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# neverthrow

## 8.1.0

### Minor Changes

- [#589](https://github.com/supermacro/neverthrow/pull/589) [`609b398`](https://github.com/supermacro/neverthrow/commit/609b398aa1fd258a1fede974707d54eb4c230f3c) Thanks [@dmmulroy](https://github.com/dmmulroy)! - safeTry should not require .safeUnwrap()

## 8.0.0

### Major Changes
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ const result = Result.combineWithAllErrors(resultList)

#### `Result.safeUnwrap()`

**⚠️ You must use `.safeUnwrap` in a generator context with `safeTry`**. Please see [safeTry](#safeTry).
**Deprecated**. You don't need to use this method anymore.

Allows for unwrapping a `Result` or returning an `Err` implicitly, thereby reducing boilerplate.

Expand Down Expand Up @@ -1412,7 +1412,7 @@ const result = ResultAsync.combineWithAllErrors(resultList)

#### `ResultAsync.safeUnwrap()`

**⚠️ You must use `.safeUnwrap` in a generator context with `safeTry`**. Please see [safeTry](#safeTry).
**Deprecated**. You don't need to use this method anymore.

Allows for unwrapping a `Result` or returning an `Err` implicitly, thereby reducing boilerplate.

Expand Down Expand Up @@ -1492,13 +1492,11 @@ function myFunc(): Result<number, string> {
// aborted here and the enclosing `safeTry` block is evaluated to that `Err`.
// Otherwise, this `(yield* ...)` is evaluated to its `.value`.
(yield* mayFail1()
.mapErr(e => `aborted by an error from 1st function, ${e}`)
.safeUnwrap())
.mapErr(e => `aborted by an error from 1st function, ${e}`))
+
// The same as above.
(yield* mayFail2()
.mapErr(e => `aborted by an error from 2nd function, ${e}`)
.safeUnwrap())
.mapErr(e => `aborted by an error from 2nd function, ${e}`))
)
})
}
Expand All @@ -1520,13 +1518,11 @@ function myFunc(): Promise<Result<number, string>> {
return ok(
// You have to await if the expression is Promise<Result>
(yield* (await mayFail1())
.mapErr(e => `aborted by an error from 1st function, ${e}`)
.safeUnwrap())
.mapErr(e => `aborted by an error from 1st function, ${e}`))
+
// You can call `safeUnwrap` directly if its ResultAsync
(yield* mayFail2()
.mapErr(e => `aborted by an error from 2nd function, ${e}`)
.safeUnwrap())
.mapErr(e => `aborted by an error from 2nd function, ${e}`))
)
})
}
Expand Down
Loading

0 comments on commit 73c78d0

Please sign in to comment.