traverseJobResultA
List.traverseJobResultA
('a -> Job<Result<'b, 'c>>) -> 'a list -> Job<Result<'b list, 'c list>>Examples
Example 1
// string -> Job<Result<int, string>>
let tryParseIntJob str =
job {
match System.Int32.TryParse str with
| true, x -> return Ok x
| false, _ -> return Error (sprintf "unable to parse '%s' to integer" str)
}
["1"; "2"; "3"]
|> List.traverseJobResultA tryParseIntJob
// job { return Ok [1; 2; 3] }
["1"; "foo"; "3"; "bar"]
|> List.traverseJobResultA tryParseIntJob
// job { return Error ["unable to parse 'foo' to integer"; "unable to parse 'bar' to integer"] }
// collects all errorsExample 2
Last updated