LanguageExt.Core

LanguageExt.Core Traits Choice

Contents

class ChoiceExtensions Source #

A semigroup on applicative functors

Methods

method K<F, A> Choose <F, A> (this K<F, A> fa, K<F, A> fb) Source #

where F : Choice<F>

Where F defines some notion of failure or choice, this function picks the first argument that succeeds. So, if fa succeeds, then fa is returned; if it fails, then fb is returned.

Parameters

type F

Alternative structure type

type A

Bound value type

param fa

First structure to test

param fb

Second structure to return if the first one fails

returns

First argument to succeed

method K<F, Seq<A>> Some <F, A> (this K<F, A> v) Source #

where F : Choice<F>

One or more...

Run the applicative functor repeatedly, collecting the results, until failure.

Will always succeed if at least one item has been yielded.

Parameters

param v

Applicative functor

returns

One or more values

method K<F, Seq<A>> Many <F, A> (this K<F, A> v) Source #

where F : Choice<F>

Zero or more...

Run the applicative functor repeatedly, collecting the results, until failure.

Will always succeed.

Parameters

param v

Applicative functor

returns

Zero or more values

class ChoiceLaw <F> Source #

where F : Choice<F>

Functions that test that Alternative laws hold for the F Alternative provided.

NOTE: Equals must be implemented for the K<F, *> derived-type, so that the laws can be proven to be true. If your Alternative structure doesn't have Equals then you must provide the optional equals parameter so that the equality of outcomes can be tested.

Parameters

type F

Alternative type

Methods

method Unit assert (Func<K<F, int>, K<F, int>, bool>? equals = null) Source #

Assert that the Alternative laws hold

NOTE: Equals must be implemented for the K<F, *> derived-type, so that the laws can be proven to be true. If your Alternative structure doesn't have Equals then you must provide the optional equals parameter so that the equality of outcomes can be tested.

method Validation<Error, Unit> validate (Func<K<F, int>, K<F, int>, bool>? equals = null) Source #

Validate that the Alternative laws hold

NOTE: Equals must be implemented for the K<F, *> derived-type, so that the laws can be proven to be true. If your Alternative structure doesn't have Equals then you must provide the optional equals parameter so that the equality of outcomes can be tested.

method Validation<Error, Unit> leftCatchLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #

Left catch law

choose(pure(x), pure(y)) = pure(x)

NOTE: Equals must be implemented for the K<F, *> derived-type, so that the laws can be proven to be true. If your Alternative structure doesn't have Equals then you must provide the optional equals parameter so that the equality of outcomes can be tested.

class Choice Source #

Methods

method K<F, A> choose <F, A> (K<F, A> fa, K<F, A> fb) Source #

where F : Choice<F>

Where F defines some notion of failure or choice, this function picks the first argument that succeeds. So, if fa succeeds, then fa is returned; if it fails, then fb is returned.

Parameters

type F

Alternative structure type

type A

Bound value type

param fa

First structure to test

param fb

Second structure to return if the first one fails

returns

First argument to succeed

method K<F, Seq<A>> some <F, A> (K<F, A> fa) Source #

where F : Choice<F>, Applicative<F>

One or more...

Run the applicative functor repeatedly, collecting the results, until failure.

Will always succeed if at least one item has been yielded.

NOTE: It is important that the F applicative-type overrides Apply (the one with Func laziness) in its trait-implementations otherwise this will likely result in a stack-overflow.

Parameters

param fa

Applicative functor

returns

One or more values

method K<F, Seq<A>> many <F, A> (K<F, A> fa) Source #

where F : Choice<F>, Applicative<F>

Zero or more...

Run the applicative functor repeatedly, collecting the results, until failure. Will always succeed.

NOTE: It is important that the F applicative-type overrides ApplyLazy in its trait-implementations otherwise this will likely result in a stack-overflow.

Parameters

param fa

Applicative functor

returns

Zero or more values

class Prelude Source #

Methods

method K<F, A> choose <F, A> (K<F, A> fa, K<F, A> fb) Source #

where F : Choice<F>

Where F defines some notion of failure or choice, this function picks the first argument that succeeds. So, if fa succeeds, then fa is returned; if it fails, then fb is returned.

Parameters

type F

Alternative structure type

type A

Bound value type

param fa

First structure to test

param fb

Second structure to return if the first one fails

returns

First argument to succeed

method K<F, Seq<A>> some <F, A> (K<F, A> fa) Source #

where F : Choice<F>, Applicative<F>

One or more...

Run the applicative functor repeatedly, collecting the results, until failure.

Will always succeed if at least one item has been yielded.

NOTE: It is important that the F applicative-type overrides Apply (the one with Func laziness) in its trait-implementations otherwise this will likely result in a stack-overflow.

Parameters

param fa

Applicative functor

returns

One or more values

method K<F, Seq<A>> many <F, A> (K<F, A> fa) Source #

where F : Choice<F>, Applicative<F>

Zero or more...

Run the applicative functor repeatedly, collecting the results, until failure. Will always succeed.

NOTE: It is important that the F applicative-type overrides ApplyLazy in its trait-implementations otherwise this will likely result in a stack-overflow.

Parameters

param fa

Applicative functor

returns

Zero or more values

interface Choice <F> Source #

where F : Choice<F>

A semigroup on applicative functors

Parameters

type F