Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (26 sloc) 906 Bytes

Result Computation Expression

Namespace: FsToolkit.ErrorHandling.CE.Result

Examples:

Example 1

The example that we saw in the Result.map3 can be solved using the result computation expression as below

open FsToolkit.ErrorHandling.CE.Result

// Result<int, string>
let addResult = result {
  let! x = tryParseInt "35"
  let! y = tryParseInt "5"
  let! z = tryParseInt "2"
  return add x y z
} // returns - Ok 42
 

Example 2

The example that we saw in the Result.map3 can be solved using the result computation expression as below

// Result<CreatePostRequest,string>
let createPostRequestResult = result {
  let! lat = Latitude.TryCreate 13.067439
  let! lng = Longitude.TryCreate 80.237617
  let! tweet = Tweet.TryCreate "Hello, World!"
  return createPostRequest userId lat lng tweet
}