map

JobResultOption.map

Namespace: FsToolkit.ErrorHandling

Function Signature:

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

Examples

Note: Many use-cases requiring map operations can also be solved using the jobResultOption computation expression.

Example 1

Given the function

getUserById : UserId -> Job<Result<User option, exn>>

Then using JobResultOption.map we can get the name of the user like this:

// Job<Result<PersonName option, exn>>
getUserById sampleUserId
|> JobResultOption.map (fun user -> user.Name)

Example 2

// Job<Result<int option, string>>
let parseFirstItem = JobResult.singleton (Some "42")

parseFirstItem
|> JobResultOption.map int
// job { return Ok (Some 42) }

Last updated