Skip to content

Commit 4c12451

Browse files
committed
add requireSomeWith doc
1 parent f5a1c85 commit 4c12451

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

gitbook/result/requireFunctions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ let result : Result<unit, string> =
6464
// Error "Value must be false"
6565
```
6666

67-
## requireSome
67+
## requireSomeWith
6868

69-
Converts an Option to a Result, using the given error if None.
69+
Converts an Option to a Result, using the given function to supply an error if None.
7070

7171
### Function Signature
7272

@@ -81,7 +81,7 @@ Converts an Option to a Result, using the given error if None.
8181
```fsharp
8282
let result : Result<unit, string> =
8383
Some 1
84-
|> Result.requireSome "Value must be Some"
84+
|> Result.requireSomeWith (fun () -> "Value must be Some")
8585
8686
// Ok ()
8787
```
@@ -91,7 +91,7 @@ let result : Result<unit, string> =
9191
```fsharp
9292
let result : Result<unit, string> =
9393
None
94-
|> Result.requireSome "Value must be Some"
94+
|> Result.requireSomeWith (fun () -> "Value must be Some")
9595
9696
// Error "Value must be Some"
9797
```

src/FsToolkit.ErrorHandling/Result.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ module Result =
307307
| Some x -> Ok x
308308
| None -> Error error
309309

310+
/// <summary>
311+
/// Returns the contained value if <c>Some</c>, otherwise evaluates <param name="ifErrorThunk"/> and returns the value.
312+
///
313+
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#requireSomeWith</href>
314+
/// </summary>
315+
/// <param name="ifErrorThunk">The function to evaluate if the result is <c>Error</c>.</param>
316+
/// <param name="option">The input result.</param>
317+
/// <returns>The contained value if <c>Some</c>, otherwise the result of evaluating <paramref name="ifErrorThunk"/>.</returns>
310318
let inline requireSomeWith
311319
(ifErrorThunk: unit -> 'error)
312320
(option: 'ok option)

0 commit comments

Comments
 (0)