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.
Note: Many use-cases requiring map operations can also be solved using the cancellableTaskValidation computation expression.
Transforming the inner value of a successful validation:
let postIdResult : CancellableTaskValidation<Guid, string> =
savePost createPostRequest
|> CancellableTaskValidation.map (fun (PostId postId) -> postId)Mapping a domain type to a DTO for serialization:
let getUserDto (userId: UserId) : CancellableTaskValidation<UserDto, string> =
fetchUser userId
|> CancellableTaskValidation.map UserDto.ofDomainChaining multiple transformations:
let getDisplayName (userId: UserId) : CancellableTaskValidation<string, string> =
fetchUser userId
|> CancellableTaskValidation.map (fun user -> $"{user.FirstName} {user.LastName}")