Validation<'TValue, 'TError> Type
Applicative validation: collects ALL errors instead of short-circuiting.
Use and! in the validation { } CE to run validators in parallel and collect errors.
Example
let validateName name =
if String.IsNullOrWhiteSpace name then Validation.error "Name required"
else Validation.ok name
let validateAge age =
if age < 0 || age > 150 then Validation.error "Invalid age"
else Validation.ok age
validation {
let! name = validateName input.Name
and! age = validateAge input.Age
return { Name = name; Age = age }
}
// If both fail: Error ["Name required"; "Invalid age"]
val validateName: name: 'a -> 'b
val name: 'a
module String
from Microsoft.FSharp.Core
val validateAge: age: int -> 'a
val age: int
Union cases
| Union case |
Description
|
Full Usage:
Error 'TError list
Parameters:
'TError list
|
|
Full Usage:
Ok 'TValue
Parameters:
'TValue
|
|
Instance members
| Instance member |
Description
|
Full Usage:
this.IsError
Returns: bool
|
|
Full Usage:
this.IsOk
Returns: bool
|
|
TDesu.FSharp