Skip to content

Commit

Permalink
start adding docs
Browse files Browse the repository at this point in the history
  • Loading branch information
joprice committed Jan 11, 2025
1 parent 4c12451 commit 2b8c474
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions gitbook/result/requireFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ let result : Result<unit, string> =
// Error "Value must be false"
```

## requireSome

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

### Function Signature

```fsharp
'a -> 'b option -> Result<'b, 'a>
```

### Examples

#### Example 1

```fsharp
let result : Result<unit, string> =
Some 1
|> Result.requireSome "Value must be Some"
// Ok ()
```

#### Example 2

```fsharp
let result : Result<unit, string> =
None
|> Result.requireSome "Value must be Some"
// Error "Value must be Some"
```

## requireSomeWith

Converts an Option to a Result, using the given function to supply an error if None.
Expand Down
4 changes: 2 additions & 2 deletions src/FsToolkit.ErrorHandling/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ module Result =
///
/// Documentation is found here: <href>https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/others#requireSomeWith</href>
/// </summary>
/// <param name="ifErrorThunk">The function to evaluate if the result is <c>Error</c>.</param>
/// <param name="option">The input result.</param>
/// <param name="ifErrorThunk">The function to evaluate if the result is <c>None</c>.</param>
/// <param name="option">The input option.</param>
/// <returns>The contained value if <c>Some</c>, otherwise the result of evaluating <paramref name="ifErrorThunk"/>.</returns>
let inline requireSomeWith
(ifErrorThunk: unit -> 'error)
Expand Down

0 comments on commit 2b8c474

Please sign in to comment.