singleton

CancellableTaskValidation.singleton

Namespace: FsToolkit.ErrorHandling

Lifts a value into a CancellableTaskValidation, wrapping it as an Ok result. This is the primary way to create a successful CancellableTaskValidation value.

Function Signature:

'item -> CancellableTaskValidation<'item, 'Error>

Examples

Example 1

let result : CancellableTaskValidation<int, string> =
  CancellableTaskValidation.singleton 42

Example 2

Using singleton inside a pipeline to return a validated value:

let validateAge (age: int) : CancellableTaskValidation<int, string> =
  if age >= 0 then CancellableTaskValidation.singleton age
  else CancellableTaskValidation.error "Age must be non-negative"

Last updated