orElse Functions

Result.orElse

Namespace: FsToolkit.ErrorHandling

Returns the result if the result is Ok, otherwise returns the given result

Function Signature

Result<'ok, 'errorOutput> -> Result<'ok, 'error> 
    -> Result<'ok, 'errorOutput>

Examples

Example 1

let result : Result<int, string> =
    Ok 1
    |> Result.orElse (Ok 2)
    
// Ok 1

Example 2

let result : Result<int, string> =
    Ok 1
    |> Result.orElse (Error "Error")
    
// Ok 1

Example 3

Example 4

Result.orElseWith

Namespace: FsToolkit.ErrorHandling

Returns the result if the result is Ok, otherwise evaluates the given function and returns the result.

Function Signature

Examples

Example 1

Example 2

Example 3

Example 4

Last updated