LanguageExt.Core

LanguageExt.Core Monads Alternative Value Monads Validation

Contents

Sub modules

Old Seq version, maybe for deletion

record Validation <F, A> Source #

where F : Monoid<F>

Like Either but collects the failed values

Parameters

type MonoidFail
type F
type A

Properties

property bool IsSuccess Source #

Is the Validation in a Success state?

property bool IsFail Source #

Is the Validation in a Fail state?

property Validation<F, A> Empty Source #

Monoid empty

Methods

method Validation<F, A> Success (A value) Source #

method Validation<F, A> Fail (F value) Source #

method B Match <B> (Func<A, B> Succ, Func<F, B> Fail) Source #

Invokes the Success or Fail function depending on the state of the Validation

Parameters

type B

Return type

param Fail

Function to invoke if in a Fail state

param Succ

Function to invoke if in a Success state

returns

The return value of the invoked function

method ReadOnlySpan<F> FailSpan () Source #

Empty span

method ReadOnlySpan<A> SuccessSpan () Source #

Span of right value

method int CompareTo <OrdF, OrdA> (Validation<F, A> other) Source #

where OrdF : Ord<F>
where OrdA : Ord<A>

Compare this structure to another to find its relative ordering

method bool Equals <EqF, EqA> (Validation<F, A> other) Source #

where EqF : Eq<F>
where EqA : Eq<A>

Equality override

method Validation<F, B> Map <B> (Func<A, B> f) Source #

Maps the value in the Validation if it's in a Success state

Parameters

type F

Fail

type A

Success

type B

Mapped Validation type

param f

Map function

returns

Mapped Validation

method Validation<F1, A1> BiMap <F1, A1> (Func<A, A1> Succ, Func<F, F1> Fail) Source #

where F1 : Monoid<F1>

Bi-maps the value in the Validation if it's in a Success state

Parameters

type F

Fail

type A

Success

type F1

Fail return

type A1

Success return

param Succ

Success map function

param Fail

Fail map function

returns

Mapped Validation

method Validation<F, B> Bind <B> (Func<A, Validation<F, B>> f) Source #

Monadic bind

Parameters

type F

Fail

type A

Success

type B

Resulting bound value

param f

Bind function

returns

Bound Validation

method Validation<F1, A1> BiBind <F1, A1> ( Func<A, Validation<F1, A1>> Succ, Func<F, Validation<F1, A1>> Fail) Source #

where F1 : Monoid<F1>

Bi-bind. Allows mapping of both monad states

method Unit Match (Action<A> Succ, Action<F> Fail) Source #

Invokes the Succ or Fail action depending on the state of the value

Parameters

param Succ

Action to invoke if in a Success state

param Fail

Action to invoke if in a Fail state

returns

Unit

method A IfFail (Func<A> Fail) Source #

Executes the Fail function if the value is in a Fail state. Returns the Success value if the value is in a Success state.

Parameters

param Fail

Function to generate a value if in the Fail state

returns

Returns an unwrapped value

method A IfFail (Func<F, A> failMap) Source #

Executes the failMap function if the value is in a Fail state. Returns the Success value if in a Success state.

Parameters

param failMap

Function to generate a value if in the Fail state

returns

Returns an unwrapped value

method A IfFail (A successValue) Source #

Returns the successValue if in a Fail state. Returns the Success value if in a Success state.

Parameters

param successValue

Value to return if in the Fail state

returns

Returns an unwrapped value

method Unit IfFail (Action<F> Fail) Source #

Executes the Fail action if in a Fail state.

Parameters

param Fail

Function to generate a Success value if in the Fail state

returns

Returns unit

method Unit IfRight (Action<A> Success) Source #

Invokes the Success action if in a Success state, otherwise does nothing

Parameters

param Success

Action to invoke

returns

Unit

method ValidationUnitContext<F, A> Success (Action<A> success) Source #

Match Success and return a context. You must follow this with .Fail(...) to complete the match

Parameters

param success

Action to invoke if in a Success state

returns

Context that must have Fail() called upon it.

method ValidationContext<F, A, B> Success <B> (Func<A, B> success) Source #

Match Success and return a context. You must follow this with .Fail(...) to complete the match

Parameters

param success

Action to invoke if in a Success state

returns

Context that must have Fail() called upon it.

method int CompareTo (object? obj) Source #

method IEnumerator<A> GetEnumerator () Source #

method Lst<F> FailToList () Source #

Project the value into a Lst<F>

Parameters

returns

If in a Fail state, a Lst of L with one item. A zero length Lst of L otherwise

method Arr<F> FailToArray () Source #

Project into an Arr<F>

Parameters

returns

If in a Fail state, a Arr of L with one item. A zero length Arr of L otherwise

method Lst<A> ToList () Source #

Project into a Lst<A>

Parameters

returns

If in a Success state, a Lst of R with one item. A zero length Lst of R otherwise

method Arr<A> ToArray () Source #

Project into an Arr<A>

Parameters

returns

If in a Success state, an Arr of R with one item. A zero length Arr of R otherwise

method Seq<A> ToSeq () Source #

Convert to sequence of 0 or 1 success values

method Seq<F> FailToSeq () Source #

Convert either to sequence of 0 or 1 left values

method Either<F, A> ToEither () Source #

method Option<A> ToOption () Source #

Convert to an Option

Parameters

returns

Some(Right) or None

method Sum<F, A> ToSum () Source #

method int CompareTo (Validation<F, A>? other) Source #

CompareTo override

method int CompareTo <OrdR> (Validation<F, A> other) Source #

where OrdR : Ord<A>

CompareTo override

method int CompareTo (Fail<F> other) Source #

CompareTo override

method int CompareTo (Pure<A> other) Source #

CompareTo override

method int CompareTo (A? other) Source #

CompareTo override

method int CompareTo (F? other) Source #

CompareTo override

method bool Equals (A? other) Source #

Equality override

method bool Equals (F? other) Source #

Equality override

method bool Equals (Validation<F, A>? other) Source #

Equality override

method bool Equals <EqR> (Validation<F, A> other) Source #

where EqR : Eq<A>

Equality override

method bool Equals (Fail<F> other) Source #

Equality override

method bool Equals (Pure<A> other) Source #

Equality override

method B MatchUntyped <B> (Func<object?, B> Succ, Func<object?, B> Fail) Source #

Match the Success and Fail values but as untyped objects.

method Unit Iter (Action<A> Succ) Source #

Iterate the value action is invoked if in the Success state

method bool ForAll (Func<A, bool> Succ) Source #

Invokes a predicate on the success value if it's in the Success state

Parameters

returns

True if in a Left state. True if the in a Right state and the predicate returns True. False otherwise.

method bool BiForAll (Func<A, bool> Succ, Func<F, bool> Fail) Source #

Invokes a predicate on the values

Parameters

type L

Left

type R

Right

param self

Either to forall

param Succ

Predicate

param Fail

Predicate

returns

True if either Predicate returns true

method S Fold <S> (S state, Func<S, A, S> Succ) Source #

Validation types are like lists of 0 or 1 items and therefore follow the same rules when folding.

Parameters

type S

Aggregate state type

param state

Initial state

param Succ

Folder function, applied if structure is in a Success state

returns

The aggregate state

method S BiFold <S> (S state, Func<S, A, S> Succ, Func<S, F, S> Fail) Source #

Either types are like lists of 0 or 1 items, and therefore follow the Validation types are like lists of 0 or 1 items and therefore follow the same rules when folding.

Parameters

type S

Aggregate state type

param state

Initial state

param Succ

Folder function, applied if in a Success state

param Fail

Folder function, applied if in a Fail state

returns

The aggregate state

method bool Exists (Func<A, bool> pred) Source #

Invokes a predicate on the value if it's in the Success state

Parameters

param pred

Predicate

returns

True if in a Success state and the predicate returns True. False otherwise.

method Validation<F, A> Do (Action<A> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method K<AF, Validation<F, B>> Traverse <AF, B> (Func<A, K<AF, B>> f) Source #

where AF : Applicative<AF>

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

Parameters

type F

Applicative functor trait

type B

Bound value (output)

param f
param ta

Traversable structure

method Validation<F1, A> MapFail <F1> (Func<F, F1> f) Source #

where F1 : Monoid<F1>

Maps the value in the Either if it's in a Left state

Parameters

type L

Left

type R

Right

type F1

Mapped Either type

param f

Map function

returns

Mapped Either

method Validation<F, B> Bind <B> (Func<A, K<Validation<F>, B>> f) Source #

Monadic bind

Parameters

type L

Left

type R

Right

type B
param f
returns

Bound Either

method Validation<F, A> Filter (Func<A, bool> pred) Source #

Filter the Validation

If the predicate returns false then the Validation goes into a failed state using Monoid.Empty of F as its failure value.

method Validation<F, A> Where (Func<A, bool> pred) Source #

Filter the Validation

If the predicate returns false then the Validation goes into a failed state using Monoid.Empty of F as its failure value.

method Validation<F, B> Select <B> (Func<A, B> f) Source #

Maps the bound value

method Validation<F, B> SelectMany <S, B> (Func<A, Validation<F, S>> bind, Func<A, S, B> project) Source #

Monadic bind function

method Validation<F, B> Bind <B> (Func<A, Pure<B>> f) Source #

Monadic bind

Parameters

param f

Bind function

method Validation<F, A> Bind (Func<A, Fail<F>> f) Source #

Monadic bind

Parameters

param f

Bind function

method Validation<F, Unit> Bind (Func<A, Guard<F, Unit>> f) Source #

Monadic bind

Parameters

param f

Bind function

method Validation<F, C> SelectMany <B, C> (Func<A, Pure<B>> bind, Func<A, B, C> project) Source #

Monadic bind and project

Parameters

param bind

Bind function

param project

Project function

method Validation<F, C> SelectMany <B, C> (Func<A, Fail<F>> bind, Func<A, B, C> _) Source #

Monadic bind and project

Parameters

param bind

Bind function

param project

Project function

method Validation<F, C> SelectMany <C> ( Func<A, Guard<F, Unit>> f, Func<A, Unit, C> project) Source #

Monadic bind and project

Parameters

param bind

Bind function

param project

Project function

method int GetHashCode () Source #

Operators

operator < (Validation<F, A> lhs, Fail<F> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator <= (Validation<F, A> lhs, Fail<F> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator > (Validation<F, A> lhs, Fail<F> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator >= (Validation<F, A> lhs, Fail<F> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator < (Validation<F, A> lhs, Pure<A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator <= (Validation<F, A> lhs, Pure<A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator > (Validation<F, A> lhs, Pure<A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator >= (Validation<F, A> lhs, Pure<A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator < (Fail<F> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator <= (Fail<F> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator > (Fail<F> lhs, Validation<F, A>rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator >= (Fail<F> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator < (Pure<A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator <= (Pure<A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator > (Pure<A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator >= (Pure<A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator < (Validation<F, A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs < rhs

operator <= (Validation<F, A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs <= rhs

operator > (Validation<F, A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs > rhs

operator >= (Validation<F, A> lhs, Validation<F, A> rhs) Source #

Comparison operator

Parameters

param lhs

The left hand side of the operation

param rhs

The right hand side of the operation

returns

True if lhs >= rhs

operator == (Validation<F, A> lhs, Fail<F> rhs) Source #

Equality operator override

operator == (Validation<F, A> lhs, Pure<A> rhs) Source #

Equality operator override

operator == (Fail<F> lhs, Validation<F, A> rhs) Source #

Equality operator override

operator == (Pure<A> lhs, Validation<F, A> rhs) Source #

Equality operator override

operator != (Validation<F, A> lhs, Fail<F> rhs) Source #

Non-equality operator override

operator != (Validation<F, A> lhs, Pure<A> rhs) Source #

Non-equality operator override

operator != (Fail<F> lhs, Validation<F, A> rhs) Source #

Non-equality operator override

operator != (Pure<A> lhs, Validation<F, A> rhs) Source #

Non-equality operator override

operator | (Validation<F, A> lhs, Validation<F, A> rhs) Source #

If any items are Fail then the errors are collected and returned. If they all pass then the first successful item is returned.

operator & (Validation<F, A> lhs, Validation<F, A> rhs) Source #

If any items are Fail then the errors are collected and returned. If they all pass then the Success values are collected into a Seq.

operator & (Validation<F, Seq<A>> lhs, Validation<F, A> rhs) Source #

If any items are Fail then the errors are collected and returned. If they all pass then the Success values are collected into a Seq.

operator & (Validation<F, A> lhs, Validation<F, Seq<A>> rhs) Source #

If any items are Fail then the errors are collected and returned. If they all pass then the Success values are collected into a Seq.

operator & (Validation<F, A> lhs, Pure<A> rhs) Source #

Override of the Or operator to be a Left coalescing operator

operator | (Validation<F, A> lhs, Pure<A> rhs) Source #

Override of the Or operator to be a Left coalescing operator

operator & (Validation<F, A> lhs, Fail<F> rhs) Source #

Override of the Or operator to be a Left coalescing operator

operator | (Validation<F, A> lhs, Fail<F> rhs) Source #

Override of the Or operator to be a Left coalescing operator

operator true (Validation<F, A> value) Source #

Override of the True operator to return True if the Either is Right

operator false (Validation<F, A> value) Source #

Override of the False operator to return True if the Either is Left

struct ValidationContext <F, A, B> Source #

where F : Monoid<F>

Context for the fluent Either matching

Methods

method B Fail (Func<F, B> fail) Source #

Fail match

Parameters

param Fail
returns

Result of the match

struct ValidationUnitContext <F, A> Source #

where F : Monoid<F>

Context for the fluent Validation matching

Methods

method Unit Left (Action<F> fail) Source #

class ValidationExtensions Source #

Methods

method Validation<F, A> As <F, A> (this K<Validation<F>, A> ma) Source #

where F : Monoid<F>

method Validation<L, A> Flatten <L, A> (this Validation<L, Validation<L, A>> mma) Source #

where L : Monoid<L>

Monadic join

method Validation<L, B> Apply <L, A, B> (this Validation<L, Func<A, B>> mf, Validation<L, A> ma) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, C> Apply <L, A, B, C> ( this Validation<L, Func<A, B, C>> mf, Validation<L, A> ma, Validation<L, B> mb) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, Func<B, C>> Apply <L, A, B, C> ( this Validation<L, Func<A, B, C>> mf, Validation<L, A> ma) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, B> ApplyM <L, A, B> ( this Validation<L, Func<A, Validation<L, B>>> mf, Validation<L, A> ma) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, C> ApplyM <L, A, B, C> ( this Validation<L, Func<A, B, Validation<L, C>>> mf, Validation<L, A> ma, Validation<L, B> mb) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, Func<B, Validation<L, C>>> ApplyM <L, A, B, C> ( this Validation<L, Func<A, B, Validation<L, C>>> mf, Validation<L, A> ma) Source #

where L : Monoid<L>

Applicative apply

method Validation<L, B> Action <L, A, B> (this Validation<L, A> ma, Validation<L, B> mb) Source #

where L : Monoid<L>

Applicative action

method IEnumerable<S> Successes <F, S> (this IEnumerable<Validation<F, S>> vs) Source #

where F : Monoid<F>

Extract only the successes

Parameters

type F

Fail type

type S

Success type

param vs

Enumerable of validations

returns

Enumerable of successes

method IEnumerable<F> Fails <F, S> (this IEnumerable<Validation<F, S>> vs) Source #

where F : Monoid<F>

Extract only the failures

Parameters

type F

Fail type

type S

Success type

param vs

Enumerable of validations

returns

Enumerable of failures

method Seq<S> Successes <F, S> (this Seq<Validation<F, S>> vs) Source #

where F : Monoid<F>

Extract only the successes

Parameters

type F

Fail type

type S

Success type

param vs

Seq of validations

returns

Enumerable of successes

method Seq<F> Fails <F, S> (this Seq<Validation<F, S>> vs) Source #

where F : Monoid<F>

Extract only the failures

Parameters

type F

Fail type

type S

Success type

param vs

Seq of validations

returns

Enumerable of failures

record Fail <F, A> (F Value) Source #

where F : Monoid<F>

Properties

property bool IsSuccess Source #

Is the Validation in a Success state?

property bool IsFail Source #

Is the Validation in a Fail state?

Methods

method B Match <B> (Func<A, B> Succ, Func<F, B> Fail) Source #

Invokes the Success or Fail function depending on the state of the Validation

Parameters

type B

Return type

param Succ

Function to invoke if in a Success state

param Fail

Function to invoke if in a Fail state

returns

The return value of the invoked function

method string ToString () Source #

Show the structure as a string

method int GetHashCode () Source #

Get a hash code for the structure

method ReadOnlySpan<F> FailSpan () Source #

Span of left value

method ReadOnlySpan<A> SuccessSpan () Source #

Empty span

method int CompareTo <OrdF, OrdA> (Validation<F, A> other) Source #

Compare this structure to another to find its relative ordering

method bool Equals <EqF, EqA> (Validation<F, A> other) Source #

Equality override

method Validation<F, B> Map <B> (Func<A, B> f) Source #

Maps the value in the Validation if it's in a Success state

Parameters

type F

Fail

type A

Success

type B

Mapped Validation type

param f

Map function

returns

Mapped Validation

method Validation<L2, R2> BiMap <L2, R2> (Func<A, R2> Succ, Func<F, L2> Fail) Source #

Bi-maps the value in the Validation if it's in a Success state

Parameters

type F

Fail

type A

Success

type L2

Fail return

type R2

Success return

param Succ

Success map function

param Fail

Fail map function

returns

Mapped Validation

method Validation<F, B> Bind <B> (Func<A, Validation<F, B>> f) Source #

Monadic bind

Parameters

type F

Fail

type A

Success

type B

Resulting bound value

param f

Bind function

returns

Bound Validation

method Validation<L2, R2> BiBind <L2, R2> ( Func<A, Validation<L2, R2>> Succ, Func<F, Validation<L2, R2>> Fail) Source #

Bi-bind. Allows mapping of both monad states

class ValidationGuardExtensions Source #

Methods

method Validation<F, C> SelectMany <F, A, C> ( this Validation<F, A> ma, Func<A, Guard<F, Unit>> f, Func<A, Unit, C> project) Source #

where F : Monoid<F>

class Validation <FAIL> Source #

where FAIL : Monoid<FAIL>

Trait implementation for Validation

Parameters

type M

Given monad trait

class Prelude Source #

Methods

method Validation<F, A> Success <F, A> (A value) Source #

where F : Monoid<F>

Represents a successful operation

Parameters

type F

Error type

type A

Value type

param value

Value

returns

Validation applicative

method Validation<F, A> Fail <F, A> (F value) Source #

where F : Monoid<F>

Represents a failed operation

Parameters

type F

Error type

type A

Value type

param value

Error value

returns

Validation applicative

method Validation<F, A> Fail <F, A> (Seq<F> values) Source #

where F : Monoid<F>

Represents a failed operation

Parameters

type F

Error type

type A

Value type

param value

Error value

returns

Validation applicative

record Success <F, A> (A Value) Source #

where F : Monoid<F>

Properties

property bool IsSuccess Source #

Is the Validation in a Success state?

property bool IsFail Source #

Is the Validation in a Left state?

Methods

method B Match <B> ( Func<A, B> Succ, Func<F, B> Fail) Source #

Invokes the Success or Left function depending on the state of the Validation

Parameters

type B

Return type

param Left

Function to invoke if in a Left state

param Success

Function to invoke if in a Success state

returns

The return value of the invoked function

method string ToString () Source #

Show the structure as a string

method int GetHashCode () Source #

Get a hash code for the structure

method ReadOnlySpan<F> FailSpan () Source #

Empty span

method ReadOnlySpan<A> SuccessSpan () Source #

Span of right value

method int CompareTo <OrdF, OrdA> (Validation<F, A> other) Source #

Compare this structure to another to find its relative ordering

method bool Equals <EqF, EqA> (Validation<F, A> other) Source #

Equality override

method Validation<F, B> Map <B> (Func<A, B> f) Source #

Maps the value in the Validation if it's in a Success state

Parameters

type F

Left

type A

Success

type B

Mapped Validation type

param f

Map function

returns

Mapped Validation

method Validation<L2, R2> BiMap <L2, R2> ( Func<A, R2> Succ, Func<F, L2> Left) Source #

Bi-maps the value in the Validation if it's in a Success state

Parameters

type F

Left

type A

Success

type L2

Left return

type R2

Success return

param Success

Success map function

param Left

Left map function

returns

Mapped Validation

method Validation<F, B> Bind <B> (Func<A, Validation<F, B>> f) Source #

Monadic bind

Parameters

type F

Left

type A

Success

type B

Resulting bound value

param f

Bind function

returns

Bound Validation

method Validation<L2, R2> BiBind <L2, R2> ( Func<A, Validation<L2, R2>> Succ, Func<F, Validation<L2, R2>> Fail) Source #

Bi-bind. Allows mapping of both monad states