map

Namespace: FsToolkit.ErrorHandling

Function Signature:

('a -> 'b) -> Result<'a option, 'c> -> Result<'b option, 'c>

ResultOption.map is the same as Result.map Option.map.

Examples

Take the following functions for example

// string -> int
let remainingCharacters (prompt: string) =
    280 - prompt.Length

Example 1

let result =
    Ok(Some "foo") // Result<string option, 'error>
    |> ResultOption.map remainingCharacters // Result<int option, 'error>

// Ok (Some 277)

Example 2

let result =
    Ok None // Result<string option, 'error>
    |> ResultOption.map remainingCharacters // Result<int option, 'error>

// Ok None

Example 3

let result =
    Error "bad things happened" // Result<string option, string>
    |> ResultOption.map remainingCharacters // Result<int option, string>

// Error "bad things happened"

Last updated