map

CancellableTaskValidation.map

Namespace: FsToolkit.ErrorHandling

Function Signature:

('input -> 'output)
  -> CancellableTaskValidation<'input, 'error>
  -> CancellableTaskValidation<'output, 'error>

Applies a mapping function to the Ok value inside a CancellableTaskValidation. If the computation contains an Error, the mapping function is not called and the errors are propagated unchanged.

Examples

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

Example 1

Transforming the inner value of a successful validation:

let postIdResult : CancellableTaskValidation<Guid, string> =
    savePost createPostRequest
    |> CancellableTaskValidation.map (fun (PostId postId) -> postId)

Example 2

Mapping a domain type to a DTO for serialization:

Example 3

Chaining multiple transformations:

Last updated