Namespace: FsToolkit.ErrorHandling
orElse returns the original AsyncValidation if it is Ok, otherwise returns the provided alternative AsyncValidation.
AsyncValidation<'ok, 'errorOutput> -> AsyncValidation<'ok, 'errorInput> -> AsyncValidation<'ok, 'errorOutput>let result =
AsyncValidation.ok "First"
|> AsyncValidation.orElse (AsyncValidation.ok "Second")
// async { Ok "First" }let result =
AsyncValidation.error "First"
|> AsyncValidation.orElse (AsyncValidation.ok "Second")
// async { Ok "Second" }let result =
AsyncValidation.error "First"
|> AsyncValidation.orElse (AsyncValidation.error "Second")
// async { Error ["Second"] }orElseWith returns the original AsyncValidation if it is Ok, otherwise calls the given function with the error list and returns its result.
('errorInput list -> AsyncValidation<'ok, 'errorOutput>) -> AsyncValidation<'ok, 'errorInput> -> AsyncValidation<'ok, 'errorOutput>let result =
AsyncValidation.ok "First"
|> AsyncValidation.orElseWith (fun _ -> AsyncValidation.ok "Second")
// async { Ok "First" }let result =
AsyncValidation.error "First"
|> AsyncValidation.orElseWith (fun _ -> AsyncValidation.ok "Second")
// async { Ok "Second" }let result =
AsyncValidation.error "First"
|> AsyncValidation.orElseWith (fun errors ->
AsyncValidation.error $"Recovered from: %A{errors}")
// async { Error ["Recovered from: [\"First\"]"] }