mapError
Namespace: FsToolkit.ErrorHandling
mapError
takes an async validation and a normal function and returns a new async validation value based on the input error value and the function
Function Signature
('errorInput -> 'errorOutput) -> AsyncValidation<'ok, 'errorInput>
-> AsyncValidation<'ok, 'errorOutput>
Examples
Take the following functions for example
// string -> int
let getErrorCode (message: string) =
match message with
| "bad things happened" -> 1
| _ -> 0
Example 1
let result =
AsyncValidation.ok "all good" // AsyncValidation<string, string>
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>
// async { Ok "all good" }
Example 2
let result =
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>
// async { Error [1] }
Last updated