Applicative Functors are a 'stepping stone' between functors and monads – they're probably less well-known but have some interesting properties of their own when it comes to lifted expression evaluation.
Two of the major uses in language-ext is to enable automatic parallel processing of effectful computations and to automatically collect multiple errors when validating. Those aren't the only usages – all the higher-kinded-types, including the collection-types, have applicative traits.
The topic is too large to cover here, so take a look at Paul Louth's Higher-Kinds series for more information.
Contents
- Act <A, B>
- ApplicativeLaw <F>
- assert (Func<K<F, int>, K<F, int>, bool>? equals = null)
- validate (Func<K<F, int>, K<F, int>, bool>? equals = null)
- homomorphismLaw (Func<K<F, int>, K<F, int>, bool> equals)
- interchangeLaw (Func<K<F, int>, K<F, int>, bool> equals)
- identityLaw (Func<K<F, int>, K<F, int>, bool> equals)
- compositionLaw (Func<K<F, int>, K<F, int>, bool> equals)
- functorLaw (Func<K<F, int>, K<F, int>, bool> equals)
- Applicative <F>
- Pure <A> (A value)
- Apply <A, B> (K<F, Func<A, B>> mf, K<F, A> ma)
- Apply <A, B> (K<F, Func<A, B>> mf, Memo<F, A> ma)
- Apply <A, B> (Memo<F, Func<A, B>> mf, Memo<F, A> ma)
- Apply <A, B> (Memo<F, Func<A, B>> mf, K<F, A> ma)
- Action <A, B> (K<F, A> ma, K<F, B> mb)
- BackAction <A, B> (K<F, A> ma, K<F, B> mb)
- Action <A, B> (K<F, A> ma, Memo<F, B> mb)
- BackAction <A, B> (K<F, A> ma, Memo<F, B> mb)
- Action <A, B> (Memo<F, A> ma, Memo<F, B> mb)
- BackAction <A, B> (Memo<F, A> ma, Memo<F, B> mb)
- Action <A, B> (Memo<F, A> ma, K<F, B> mb)
- BackAction <A, B> (Memo<F, A> ma, K<F, B> mb)
- Actions <A> (IterableNE<K<F, A>> fas)
- Between <A, OPEN, CLOSE> ( K<F, OPEN> open, K<F, CLOSE> close, K<F, A> p)
- Replicate <A> (int count, K<F, A> fa)
Sub modules
| Extensions |
| Module |
| Operators |
| Prelude |
class ApplicativeLaw <F> Source #
Functions that test that Applicative-functor laws hold for the F applicative-functor provided.
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your applicative-functor doesn't have Equals then you must provide
the optional equals parameter so that the equality of outcomes can be tested.
Parameters
| type | F | Applicative functor type |
Methods
method Unit assert (Func<K<F, int>, K<F, int>, bool>? equals = null) Source #
Assert that the applicative-functor 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 applicative-functor 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 applicative-functor 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 applicative-functor 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> homomorphismLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #
Validate the homomorphism law
Homomorphism
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your applicative-functor 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> interchangeLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #
Validate the interchange law
Interchange
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your applicative-functor 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> identityLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #
Validate the identity law
Identity
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your applicative-functor 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> compositionLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #
Validate the composition law
Composition
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your functor 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> functorLaw (Func<K<F, int>, K<F, int>, bool> equals) Source #
Validate the functor law
Applicative-Functor
NOTE: Equals must be implemented for the K〈F, *〉 derived-type, so that the laws
can be proven to be true. If your functor doesn't have Equals then you must provide
the optional equals parameter so that the equality of outcomes can be tested.
interface Applicative <F> Source #
Applicative functor
Parameters
| type | F | Functor trait type |
| type | A | Bound value type |
Methods
method K<F, A> Pure <A> (A value) Source #
Lift a pure value into the applicative structure
Parameters
| type | A | Value type |
| param | value | Value to lift |
| returns | Constructed applicative structure | |
method K<F, B> Apply <A, B> (K<F, Func<A, B>> mf, K<F, A> ma) Source #
Apply the function to the argument.
This is like delegate.Invoke for lifted functions and lifted arguments.
Parameters
| type | A | Argument type |
| type | B | Return type |
| param | mf | Lifted function |
| param | ma | Lifted argument |
| returns | Applicative structure that represents the result of invoking the lifted function with the lifted argument | |
method K<F, B> Apply <A, B> (K<F, Func<A, B>> mf, Memo<F, A> ma) Source #
Apply the function to the argument.
This is like delegate.Invoke for lifted functions and lifted arguments.
Uses memoisation for lazy and then cached evaluation of the argument.
Parameters
| type | A | Argument type |
| type | B | Return type |
| param | mf | Lifted function |
| param | ma | Lifted argument |
| returns | Applicative structure that represents the result of invoking the lifted function with the lifted argument | |
method K<F, B> Apply <A, B> (Memo<F, Func<A, B>> mf, Memo<F, A> ma) Source #
Apply the function to the argument.
This is like delegate.Invoke for lifted functions and lifted arguments.
Uses memoisation for lazy and then cached evaluation of the argument.
Parameters
| type | A | Argument type |
| type | B | Return type |
| param | mf | Lifted function |
| param | ma | Lifted argument |
| returns | Applicative structure that represents the result of invoking the lifted function with the lifted argument | |
method K<F, B> Apply <A, B> (Memo<F, Func<A, B>> mf, K<F, A> ma) Source #
Apply the function to the argument.
This is like delegate.Invoke for lifted functions and lifted arguments.
Uses memoisation for lazy and then cached evaluation of the argument.
Parameters
| type | A | Argument type |
| type | B | Return type |
| param | mf | Lifted function |
| param | ma | Lifted argument |
| returns | Applicative structure that represents the result of invoking the lifted function with the lifted argument | |
method K<F, B> Action <A, B> (K<F, A> ma, K<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, A> BackAction <A, B> (K<F, A> ma, K<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, B> Action <A, B> (K<F, A> ma, Memo<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, A> BackAction <A, B> (K<F, A> ma, Memo<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, B> Action <A, B> (Memo<F, A> ma, Memo<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, A> BackAction <A, B> (Memo<F, A> ma, Memo<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, B> Action <A, B> (Memo<F, A> ma, K<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, A> BackAction <A, B> (Memo<F, A> ma, K<F, B> mb) Source #
Applicative action. Computes the first applicative action and then computes the second.
Parameters
| type | A | First applicative structure bound value type |
| type | B | Second applicative structure bound value type |
| param | ma | First applicative structure |
| param | mb | Second applicative structure |
| returns | The result of the second applicative action (if there wasn't a failure beforehand) | |
method K<F, A> Actions <A> (IterableNE<K<F, A>> fas) Source #
Chains a sequence of applicative actions
Because this is an abstract chaining of actions, it can't actually run anything, and so if your
actions are expected to have side effects (IO effects, for example), then you won't see them until
the resulting K〈F, A〉 is 'run'.
This matters for infinite streams, where the result of Actions isn't realised at all, and so to
avoid nothing happening (no side effects), you should override this function and unpack the IO
type within, then run that enumerable of IOs.
A good example is with the Eff type. It's a ReaderT〈IO, A〉 internally:
static K〈Eff〈RT〉, A〉 Actions〈A〉(IEnumerable〈K〈Eff〈RT〉, A〉〉 fas) =〉
new Eff〈RT, A〉(
new ReaderT〈RT, IO, A〉(
rt =〉fas.Select(fa =〉fa.RunIO(rt)).Actions()));
Parameters
| type | A | Bound value type |
| param | fas | Actions to chain |
| returns | ||
method K<F, A> Between <A, OPEN, CLOSE> ( K<F, OPEN> open, K<F, CLOSE> close, K<F, A> p) Source #
between(open, close, p) parses open, followed by pandclose`.
Parameters
| type | A | Return value type |
| type | OPEN | OPEN value type |
| type | CLOSE | CLOSE value type |
| param | open | Open computation |
| param | close | Close computation |
| param | p | Between computation |
| returns | The value returned by | |