FSharpPlus


Result Module

Additional operations on Result<'T,'Error>

Functions and values

Function or value Description

Result.apply f x

Full Usage: Result.apply f x

Parameters:
Returns: Result<'U, 'Error>

Applies the wrapped value to the wrapped function when both are Ok and returns a wrapped result or the first Error. The function wrapped in an Ok or an Error. The value wrapped in an Ok or an Error. An Ok of the function applied to the value, or the first Error if either the function or the value is Error.

f : Result<('T -> 'U), 'Error>
x : Result<'T, 'Error>
Returns: Result<'U, 'Error>

Result.apply2With combiner f x y

Full Usage: Result.apply2With combiner f x y

Parameters:
    combiner : 'Error -> 'Error -> 'Error
    f : 'T -> 'U -> 'V
    x : Result<'T, 'Error>
    y : Result<'U, 'Error>

Returns: Result<'V, 'Error>
combiner : 'Error -> 'Error -> 'Error
f : 'T -> 'U -> 'V
x : Result<'T, 'Error>
y : Result<'U, 'Error>
Returns: Result<'V, 'Error>

Result.apply3With combiner f x y z

Full Usage: Result.apply3With combiner f x y z

Parameters:
    combiner : 'Error -> 'Error -> 'Error
    f : 'T -> 'U -> 'V -> 'W
    x : Result<'T, 'Error>
    y : Result<'U, 'Error>
    z : Result<'V, 'Error>

Returns: Result<'W, 'Error>
combiner : 'Error -> 'Error -> 'Error
f : 'T -> 'U -> 'V -> 'W
x : Result<'T, 'Error>
y : Result<'U, 'Error>
z : Result<'V, 'Error>
Returns: Result<'W, 'Error>

Result.bimap errorMapper okMapper source

Full Usage: Result.bimap errorMapper okMapper source

Parameters:
    errorMapper : 'TError -> 'UError - Function to be applied to source, if it contains an Error value.
    okMapper : 'T -> 'U - Function to be applied to source, if it contains an Ok value.
    source : Result<'T, 'TError> - The source value, containing an Ok or an Error.

Returns: Result<'U, 'UError> The result of applying the corresponding mapping function.

Maps both Ok and Error of a Result.

errorMapper : 'TError -> 'UError

Function to be applied to source, if it contains an Error value.

okMapper : 'T -> 'U

Function to be applied to source, if it contains an Ok value.

source : Result<'T, 'TError>

The source value, containing an Ok or an Error.

Returns: Result<'U, 'UError>

The result of applying the corresponding mapping function.

Result.bindError binder source

Full Usage: Result.bindError binder source

Parameters:
    binder : 'Error -> Result<'T, 'Error2> - A function that takes the error and transforms it into a result.
    source : Result<'T, 'Error> - The source input value.

Returns: Result<'T, 'Error2> A result of the output type of the binder.
Modifiers: inline
Type parameters: 'Error, 'T, 'Error2

If the input value is an Ok leaves it unchanged, otherwise maps the Error value and flattens the resulting nested Result.

binder : 'Error -> Result<'T, 'Error2>

A function that takes the error and transforms it into a result.

source : Result<'T, 'Error>

The source input value.

Returns: Result<'T, 'Error2>

A result of the output type of the binder.

Result.catch x f

Full Usage: Result.catch x f

Parameters:
Returns: Result<'v, 'e>
Modifiers: inline
Type parameters: 'v, 't, 'e

Like Result.bindError but with flipped arguments.

x : Result<'v, 't>
f : 't -> Result<'v, 'e>
Returns: Result<'v, 'e>

Result.defaultValue value result

Full Usage: Result.defaultValue value result

Parameters:
    value : 'T - The specified default value.
    result : Result<'T, 'Error> - The input result.

Returns: 'T The result if the result is Ok, else the default value.

Gets the value of the result if the result is Ok, otherwise returns the specified default value.

Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

value : 'T

The specified default value.

result : Result<'T, 'Error>

The input result.

Returns: 'T

The result if the result is Ok, else the default value.

Result.defaultWith defThunk result

Full Usage: Result.defaultWith defThunk result

Parameters:
    defThunk : 'Error -> 'T - A thunk that provides a default value when evaluated.
    result : Result<'T, 'Error> - The input result.

Returns: 'T

Gets the value of the result if the result is Ok, otherwise evaluates defThunk and returns the result.

Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

defThunk : 'Error -> 'T

A thunk that provides a default value when evaluated.

result : Result<'T, 'Error>

The input result.

Returns: 'T

Result.either fOk fError source

Full Usage: Result.either fOk fError source

Parameters:
    fOk : 'T -> 'U - Function to be applied to source, if it contains an Ok value.
    fError : 'Error -> 'U - Function to be applied to source, if it contains an Error value.
    source : Result<'T, 'Error> - The source value, containing an Ok or an Error.

Returns: 'U The result of applying either functions.
Modifiers: inline
Type parameters: 'T, 'U, 'Error

Extracts a value from either side of a Result.

fOk : 'T -> 'U

Function to be applied to source, if it contains an Ok value.

fError : 'Error -> 'U

Function to be applied to source, if it contains an Error value.

source : Result<'T, 'Error>

The source value, containing an Ok or an Error.

Returns: 'U

The result of applying either functions.

Result.flatten source

Full Usage: Result.flatten source

Parameters:
    source : Result<Result<'T, 'Error>, 'Error> - The nested Results.

Returns: Result<'T, 'Error> A single Ok of the value when it was nested with OKs, or the Error.

Flattens two nested Results.

flatten is equivalent to bind id.

source : Result<Result<'T, 'Error>, 'Error>

The nested Results.

Returns: Result<'T, 'Error>

A single Ok of the value when it was nested with OKs, or the Error.

Result.get source

Full Usage: Result.get source

Parameters:
Returns: 'T

Gets the 'Ok' value. If it's an 'Error' this function will throw an exception.

source : Result<'T, 'Error>
Returns: 'T

Result.iterError action source

Full Usage: Result.iterError action source

Parameters:
    action : 'Error -> unit - A function to apply to the error part of the source value.
    source : Result<'T, 'Error> - The input result.

Modifiers: inline
Type parameters: 'Error, 'T

iterError f inp executes match inp with Ok _ -> () | Error x -> f x.

action : 'Error -> unit

A function to apply to the error part of the source value.

source : Result<'T, 'Error>

The input result.

Example

 Ok "Hello world" |> Result.iter (printfn "%s") // does nothing
 Error "Hello world" |> Result.iter (printfn "%s") // prints "Hello world"
union case Result.Ok: ResultValue: 'T -> Result<'T,'TError>
Multiple items
module Result from Microsoft.FSharp.Core

--------------------
[<Struct>] type Result<'T,'TError> = | Ok of ResultValue: 'T | Error of ErrorValue: 'TError
val iter: action: ('T -> unit) -> result: Result<'T,'Error> -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case Result.Error: ErrorValue: 'TError -> Result<'T,'TError>

Result.map2 f x y

Full Usage: Result.map2 f x y

Parameters:
    f : 'T -> 'U -> 'V - The mapping function.
    x : Result<'T, 'Error> - The first Result value.
    y : Result<'U, 'Error> - The second Result value.

Returns: Result<'V, 'Error> The combined value, or the first Error.

Creates a Result value from a pair of Result values, using a function to combine them.

f : 'T -> 'U -> 'V

The mapping function.

x : Result<'T, 'Error>

The first Result value.

y : Result<'U, 'Error>

The second Result value.

Returns: Result<'V, 'Error>

The combined value, or the first Error.

Result.map3 f x y z

Full Usage: Result.map3 f x y z

Parameters:
    f : 'T -> 'U -> 'V -> 'W - The mapping function.
    x : Result<'T, 'Error> - The first Result value.
    y : Result<'U, 'Error> - The second Result value.
    z : Result<'V, 'Error> - The third Result value.

Returns: Result<'W, 'Error> The combined value, or the first Error.

Creates a Result value from three Result values, using a function to combine them.

f : 'T -> 'U -> 'V -> 'W

The mapping function.

x : Result<'T, 'Error>

The first Result value.

y : Result<'U, 'Error>

The second Result value.

z : Result<'V, 'Error>

The third Result value.

Returns: Result<'W, 'Error>

The combined value, or the first Error.

Result.ofChoice source

Full Usage: Result.ofChoice source

Parameters:
Returns: Result<'T, 'U>

Creates a Result<'T,'Error> from a Choice<'T,'Error>.

source : Choice<'T, 'U>
Returns: Result<'T, 'U>

Result.partition source

Full Usage: Result.partition source

Parameters:
    source : Result<'T, 'Error> list

Returns: 'T list * 'Error list A tuple with both resulting lists, Oks are in the first list.

Creates two lists by classifying the values depending on whether they were wrapped with Ok or Error.

source : Result<'T, 'Error> list
Returns: 'T list * 'Error list

A tuple with both resulting lists, Oks are in the first list.

Result.protect f x

Full Usage: Result.protect f x

Parameters:
    f : 'T -> 'U
    x : 'T

Returns: Result<'U, exn>

Creates a safe version of the supplied function, which returns a Result<'U,exn> instead of throwing exceptions.

f : 'T -> 'U
x : 'T
Returns: Result<'U, exn>

Result.toChoice source

Full Usage: Result.toChoice source

Parameters:
Returns: Choice<'T, 'U>

Converts a Result<'T,'Error> to a Choice<'T,'Error>.

source : Result<'T, 'U>
Returns: Choice<'T, 'U>

Result.unzip source

Full Usage: Result.unzip source

Parameters:
    source : Result<('T * 'U), 'Error> - The value.

Returns: Result<'T, 'Error> * Result<'U, 'Error> The resulting tuple.

If value is Ok, returns both of them tupled. Otherwise it returns the Error value twice in a tuple.

source : Result<('T * 'U), 'Error>

The value.

Returns: Result<'T, 'Error> * Result<'U, 'Error>

The resulting tuple.

Result.zip x y

Full Usage: Result.zip x y

Parameters:
    x : Result<'T, 'Error> - The first Result value.
    y : Result<'U, 'Error> - The second Result value.

Returns: Result<('T * 'U), 'Error> The tupled value, or the first Error.

Creates a Result value from a pair of Result values.

x : Result<'T, 'Error>

The first Result value.

y : Result<'U, 'Error>

The second Result value.

Returns: Result<('T * 'U), 'Error>

The tupled value, or the first Error.

Result.zip3 x y z

Full Usage: Result.zip3 x y z

Parameters:
    x : Result<'T, 'Error> - The first Result value.
    y : Result<'U, 'Error> - The second Result value.
    z : Result<'V, 'Error> - The third Result value.

Returns: Result<('T * 'U * 'V), 'Error> The tupled value, or the first Error.

Creates a Result value from a three Result values.

x : Result<'T, 'Error>

The first Result value.

y : Result<'U, 'Error>

The second Result value.

z : Result<'V, 'Error>

The third Result value.

Returns: Result<('T * 'U * 'V), 'Error>

The tupled value, or the first Error.