Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 937 Bytes

File metadata and controls

28 lines (19 loc) · 937 Bytes

CancellableTaskResult Infix Operators

Namespace: FsToolkit.ErrorHandling.Operator.CancellableTaskResult

FsToolkit.ErrorHandling provides the standard infix operators for the map (<!>), apply (<*>), and bind (>>=) functions of the CancellableTask<Result<_,_>> type.

Examples:

Example 1

Expanding on the CancellableTaskResult.map2 example, we define another function:

notifyFollowers : NotifyNewPostRequest -> CancellableTask<Result<unit, exn>>

We can then rewrite the example and additionally call notifyFollowers using the operators as below:

open FsToolkit.ErrorHandling.Operator.CancellableTaskResult

// CreatePostRequest -> CancellableTask<Result<unit, exn>>
let createPostAndNotifyFollowers (req : CreatePostRequest) = 
  notifyNewPostRequest
  <!> (getFollowerIds req.UserId)
  <*> (createPost req)
  >>= notifyFollowers