Header menu logo TDesu.FSharp

Result Module

Functions and values

Function or value Description

Result.bind f r

Full Usage: Result.bind f r

Parameters:
Returns: Result<'b, 'c>
Modifiers: inline
Type parameters: 'a, 'b, 'c

Chains a Result-returning function on Ok; short-circuits on Error. The function returning a new Result. The result to bind over.

f : 'a -> Result<'b, 'c>
r : Result<'a, 'c>
Returns: Result<'b, 'c>

Result.catch f

Full Usage: Result.catch f

Parameters:
    f : unit -> 'T - The function to execute inside a try/catch.

Returns: Result<'T, exn>
Modifiers: inline
Type parameters: 'T

Wraps a function call in try/catch, returning Ok on success or Error(exn) on exception.

f : unit -> 'T

The function to execute inside a try/catch.

Returns: Result<'T, exn>
Example

 Result.catch (fun () -> int "42")   // Ok 42
 Result.catch (fun () -> int "bad")  // Error (FormatException ...)
Multiple items
module Result from Microsoft.FSharp.Core

--------------------
[<Struct>] type Result<'T,'TError> = | Ok of ResultValue: 'T | Error of ErrorValue: 'TError
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int

Result.defaultValue def r

Full Usage: Result.defaultValue def r

Parameters:
Returns: 'T
Modifiers: inline
Type parameters: 'T, 'a

Returns the Ok value, or the given default. The default value to return on Error. The result to extract from.

def : 'T
r : Result<'T, 'a>
Returns: 'T

Result.defaultWith f r

Full Usage: Result.defaultWith f r

Parameters:
    f : unit -> 'T
    r : Result<'T, 'a>

Returns: 'T
Modifiers: inline
Type parameters: 'T, 'a

Returns the Ok value, or computes a default. The function to compute a default value on Error. The result to extract from.

f : unit -> 'T
r : Result<'T, 'a>
Returns: 'T

Result.get r

Full Usage: Result.get r

Parameters:
    r : Result<'a, 'b> - The result to unwrap.

Returns: 'a
Modifiers: inline
Type parameters: 'a, 'b

Extracts the Ok value or throws InvalidOperationException on Error.

r : Result<'a, 'b>

The result to unwrap.

Returns: 'a
InvalidOperationException When the result is Error.

Result.ignore r

Full Usage: Result.ignore r

Parameters:
Returns: Result<unit, 'TError>
Modifiers: inline
Type parameters: 'a, 'TError

Discards the Ok value, preserving the Error. The result whose Ok value is discarded.

r : Result<'a, 'TError>
Returns: Result<unit, 'TError>

Result.isError r

Full Usage: Result.isError r

Parameters:
Returns: bool
Modifiers: inline
Type parameters: 'a, 'b

Returns true if the result is Error. The result to check.

r : Result<'a, 'b>
Returns: bool

Result.isOk r

Full Usage: Result.isOk r

Parameters:
Returns: bool
Modifiers: inline
Type parameters: 'a, 'b

Returns true if the result is Ok. The result to check.

r : Result<'a, 'b>
Returns: bool

Result.map f r

Full Usage: Result.map f r

Parameters:
    f : 'a -> 'b
    r : Result<'a, 'c>

Returns: Result<'b, 'c>
Modifiers: inline
Type parameters: 'a, 'b, 'c

Transforms the Ok value with f, passing Error through unchanged. The mapping function to apply to the Ok value. The result to transform.

f : 'a -> 'b
r : Result<'a, 'c>
Returns: Result<'b, 'c>

Result.mapError f r

Full Usage: Result.mapError f r

Parameters:
    f : 'a -> 'b
    r : Result<'c, 'a>

Returns: Result<'c, 'b>
Modifiers: inline
Type parameters: 'a, 'b, 'c

Transforms the Error value with f, passing Ok through unchanged. The mapping function to apply to the Error value. The result to transform.

f : 'a -> 'b
r : Result<'c, 'a>
Returns: Result<'c, 'b>

Result.ofOption error opt

Full Usage: Result.ofOption error opt

Parameters:
    error : 'TError
    opt : 'T option

Returns: Result<'T, 'TError>
Modifiers: inline
Type parameters: 'TError, 'T

Converts an Option to a Result: Some becomes Ok, None becomes Error. The error value to use when the option is None. The option to convert.

error : 'TError
opt : 'T option
Returns: Result<'T, 'TError>

Result.orElse ifError r

Full Usage: Result.orElse ifError r

Parameters:
Returns: Result<'T, 'TError>
Modifiers: inline
Type parameters: 'T, 'TError

Returns the result if Ok, otherwise the given fallback result. The fallback result to use on Error. The result to evaluate.

ifError : Result<'T, 'TError>
r : Result<'T, 'TError>
Returns: Result<'T, 'TError>

Result.orElseWith f r

Full Usage: Result.orElseWith f r

Parameters:
    f : 'TError -> Result<'T, 'TError2>
    r : Result<'T, 'TError>

Returns: Result<'T, 'TError2>
Modifiers: inline
Type parameters: 'TError, 'T, 'TError2

Returns the result if Ok, otherwise computes a fallback from the Error. The function to compute a fallback result from the Error value. The result to evaluate.

f : 'TError -> Result<'T, 'TError2>
r : Result<'T, 'TError>
Returns: Result<'T, 'TError2>

Result.requireFalse error value

Full Usage: Result.requireFalse error value

Parameters:
    error : 'TError
    value : bool

Returns: Result<unit, 'TError>
Modifiers: inline
Type parameters: 'TError

Returns Ok(()) if false, Error(error) if true. The error value to use when the condition is true. The boolean condition to check.

error : 'TError
value : bool
Returns: Result<unit, 'TError>

Result.requireNotNull error value

Full Usage: Result.requireNotNull error value

Parameters:
    error : 'TError
    value : 'T

Returns: Result<'T, 'TError>
Modifiers: inline
Type parameters: 'TError, 'T

Returns Ok(value) if not null, Error(error) if null. The error value to use when the value is null. The value to check for null.

error : 'TError
value : 'T
Returns: Result<'T, 'TError>

Result.requireTrue error value

Full Usage: Result.requireTrue error value

Parameters:
    error : 'TError
    value : bool

Returns: Result<unit, 'TError>
Modifiers: inline
Type parameters: 'TError

Returns Ok(()) if true, Error(error) if false. The error value to use when the condition is false. The boolean condition to check.

error : 'TError
value : bool
Returns: Result<unit, 'TError>

Result.tee f r

Full Usage: Result.tee f r

Parameters:
    f : 'T -> unit
    r : Result<'T, 'TError>

Returns: Result<'T, 'TError>
Modifiers: inline
Type parameters: 'T, 'TError

Applies a side-effect on Ok and returns the result unchanged. The side-effect function to apply on Ok. The result to inspect.

f : 'T -> unit
r : Result<'T, 'TError>
Returns: Result<'T, 'TError>

Result.teeError f r

Full Usage: Result.teeError f r

Parameters:
    f : 'TError -> unit
    r : Result<'T, 'TError>

Returns: Result<'T, 'TError>
Modifiers: inline
Type parameters: 'TError, 'T

Applies a side-effect on Error and returns the result unchanged. The side-effect function to apply on Error. The result to inspect.

f : 'TError -> unit
r : Result<'T, 'TError>
Returns: Result<'T, 'TError>

Result.toOption r

Full Usage: Result.toOption r

Parameters:
Returns: 'T option
Modifiers: inline
Type parameters: 'T, 'a

Converts Result to Option: Ok becomes Some, Error becomes None. The result to convert.

r : Result<'T, 'a>
Returns: 'T option

Result.valueOr f r

Full Usage: Result.valueOr f r

Parameters:
    f : 'TError -> 'T
    r : Result<'T, 'TError>

Returns: 'T
Modifiers: inline
Type parameters: 'TError, 'T

Extracts the Ok value, or computes a fallback from the Error. The function to compute a fallback from the Error value. The result to extract from.

f : 'TError -> 'T
r : Result<'T, 'TError>
Returns: 'T

Result.zip r1 r2

Full Usage: Result.zip r1 r2

Parameters:
    r1 : Result<'T1, 'TError> - The first result.
    r2 : Result<'T2, 'TError> - The second result.

Returns: Result<('T1 * 'T2), 'TError>
Modifiers: inline
Type parameters: 'T1, 'TError, 'T2

Combines two results into a tuple. Returns the first Error if any.

r1 : Result<'T1, 'TError>

The first result.

r2 : Result<'T2, 'TError>

The second result.

Returns: Result<('T1 * 'T2), 'TError>

Type something to start searching.