either

JobOption.either

Namespace: FsToolkit.ErrorHandling

Function Signature:

('a -> Job<'b>) -> Job<'b> -> Job<'a option> -> Job<'b>

Runs onSome if the job-wrapped option is Some, otherwise runs onNone.

Examples

Example 1

let tryFindUser : string -> Job<User option>

// Job<string>
tryFindUser "alice"
|> JobOption.either
    (fun user -> Job.singleton (sprintf "Found user: %s" user.Name))
    (Job.singleton "User not found")

Example 2

let maybeValue : Job<int option> = Job.singleton (Some 42)

maybeValue
|> JobOption.either
    (fun x -> Job.singleton (x * 2))
    (Job.singleton 0)
// job { return 84 }

Example 3

Last updated