Computation Expression

Last updated 2 months ago

AsyncResultOption Computation Expression

Namespace: FsToolkit.ErrorHandling.CE.AsyncResultOption

Examples

Example 1

The AsyncResultOption.bind example can be written using computation expression as below

// Post -> User -> UserTweet
let userTweet (p : Post) (u : User) =
// ...
// UserId -> Async<Result<User option, Exception>>
let getUserById (userId : UserId) = async {
// ...
}
// PostId -> Async<Result<Post option, Exception>>
let getPostById (postId : PostId) = async {
// ...
}
// Async<Result<Post option, Exception>>
asyncResultOption {
let! post = getPostById samplePostId
let! user = getUserById post.UserId
return userTweet post user
}