apply

Namespace: FsToolkit.ErrorHandling
Function Signature:
Result<('a -> 'b) option, 'c> -> Result<'a option, 'c>
-> Result<'b option, 'c>

Examples

Take the following function for example
// string -> int
let characterCount (s: string) = s.Length

Example 1

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

Example 2

let result =
Ok None // Result<string option, 'error>
|> ResultOption.apply (Ok(Some characterCount)) // Result<int option, 'error>
// Ok None

Example 3

let result =
Error "bad things happened" // Result<string option, string>
|> ResultOption.apply (Ok(Some characterCount)) // Result<int option, string>
// Error "bad things happened"
Last modified 2mo ago