orElse Functions

CancellableTaskValidation.orElse

Namespace: FsToolkit.ErrorHandling

Returns the original result unchanged if it is Ok, otherwise returns the provided alternative CancellableTaskValidation.

Note: CancellableTaskValidation accumulates errors as 'error list. The orElseWith overload receives the full error list.

Function Signature:

CancellableTaskValidation<'ok, 'errorOutput>
  -> CancellableTaskValidation<'ok, 'errorInput>
  -> CancellableTaskValidation<'ok, 'errorOutput>

Examples

Example 1

CancellableTaskValidation.error "First"
|> CancellableTaskValidation.orElse (CancellableTaskValidation.singleton "Second")
// evaluates to Ok "Second"

Example 2

When the input is already Ok, the alternative is ignored:

CancellableTaskValidation.singleton "First"
|> CancellableTaskValidation.orElse (CancellableTaskValidation.error "Second")
// evaluates to Ok "First"

CancellableTaskValidation.orElseWith

Namespace: FsToolkit.ErrorHandling

Returns the original result unchanged if it is Ok, otherwise calls the given function with the accumulated error list and returns its result. The alternative function is not evaluated unless the input is Error.

Function Signature:

Examples

Example 1

Example 2

Falling back to a secondary validation strategy when the primary fails:

Last updated