Skip to content

Commit 2b8c474

Browse files
committed
start adding docs
1 parent 4c12451 commit 2b8c474

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

gitbook/result/requireFunctions.md

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

67+
## requireSome
68+
69+
Converts an Option to a Result, using the given function to supply an error if None.
70+
71+
### Function Signature
72+
73+
```fsharp
74+
'a -> 'b option -> Result<'b, 'a>
75+
```
76+
77+
### Examples
78+
79+
#### Example 1
80+
81+
```fsharp
82+
let result : Result<unit, string> =
83+
Some 1
84+
|> Result.requireSome "Value must be Some"
85+
86+
// Ok ()
87+
```
88+
89+
#### Example 2
90+
91+
```fsharp
92+
let result : Result<unit, string> =
93+
None
94+
|> Result.requireSome "Value must be Some"
95+
96+
// Error "Value must be Some"
97+
```
98+
6799
## requireSomeWith
68100

69101
Converts an Option to a Result, using the given function to supply an error if None.

src/FsToolkit.ErrorHandling/Result.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ module Result =
312312
///
313313
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#requireSomeWith</href>
314314
/// </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>
315+
/// <param name="ifErrorThunk">The function to evaluate if the result is <c>None</c>.</param>
316+
/// <param name="option">The input option.</param>
317317
/// <returns>The contained value if <c>Some</c>, otherwise the result of evaluating <paramref name="ifErrorThunk"/>.</returns>
318318
let inline requireSomeWith
319319
(ifErrorThunk: unit -> 'error)

0 commit comments

Comments
 (0)