- ChoiceExtensions
- Choose <F, A> (this K<F, A> fa, K<F, A> fb)
- Some <F, A> (this K<F, A> v)
- Many <F, A> (this K<F, A> v)
- ChoiceLaw <F>
- assert (Func<K<F, int>, K<F, int>, bool>? equals = null)
- validate (Func<K<F, int>, K<F, int>, bool>? equals = null)
- leftCatchLaw (Func<K<F, int>, K<F, int>, bool> equals)
- Choice
- Prelude
- Choice <F>
class ChoiceExtensions Source #
A semigroup on applicative functors
method K<F, A> Choose <F, A> (this K<F, A> fa, K<F, A> fb) Source #
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.
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 |
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.
type | F | Alternative type |
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.
method K<F, A> choose <F, A> (K<F, A> fa, K<F, A> fb) Source #
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.
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 #
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.
param | fa | Applicative functor |
returns | One or more values |
method K<F, Seq<A>> many <F, A> (K<F, A> fa) Source #
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.
param | fa | Applicative functor |
returns | Zero or more values |
method K<F, A> choose <F, A> (K<F, A> fa, K<F, A> fb) Source #
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.
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 #
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.
param | fa | Applicative functor |
returns | One or more values |
method K<F, Seq<A>> many <F, A> (K<F, A> fa) Source #
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.
param | fa | Applicative functor |
returns | Zero or more values |