Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ Validation.ofOptionWith #563

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/FSharpPlus/Data/Validation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ module Validation =
/// Creates a Validation<'Error,'T> from a Choice<'T,'Error>.
let ofChoice (x: Choice<'T,'Error>) = match x with Choice1Of2 a -> Success a | Choice2Of2 e -> Failure e

/// <summary>Converts an option to a Validation.</summary>
/// <param name="errorValue">The error value to be used in case of None.</param>
/// <param name="source">The option value.</param>
/// <returns>The resulting Validation value.</returns>
let ofOptionWith (errorValue: 'Error) (source: 'T option) = match source with Some x -> Success x | None -> Failure errorValue

/// <summary>Converts a voption to a Validation.</summary>
/// <param name="errorValue">The error value to be used in case of None.</param>
/// <param name="source">The voption value.</param>
/// <returns>The resulting Validation value.</returns>
let ofValueOptionWith (errorValue: 'Error) (source: 'T voption) = match source with ValueSome x -> Success x | ValueNone -> Failure errorValue

/// <summary> Extracts a value from either side of a Validation.</summary>
/// <param name="successMapper">Function to be applied to source, if it contains a Success value.</param>
/// <param name="failureMapper">Function to be applied to source, if it contains a Failure value.</param>
Expand Down
Loading