Sequence of applicative functions from A to B: Eff[R, A => B]
Sequence of monadic functions from A to B: A => Eff[B]
Sequence of monadic functions from A to B: A => Eff[B]
Internally it is represented as a Vector of functions:
A => Eff[R, X1]; X1 => Eff[R, X2]; X2 => Eff[R, X3]; ...; X3 => Eff[R, B]
The Choose effect models non-determinism So we can get results, either:
The Choose effect models non-determinism So we can get results, either:
When running this effect we can "collect" the results with any F which has an Alternative instance.
For example if F is List then:
If F is Option then:
Effects of type R, returning a value of type A
Effects of type R, returning a value of type A
It is implemented as a "Free-er" monad with extensible effects:
Arrs
typeThe monad implementation for this type is really simple:
point
is Purebind
simply appends the binding function to the Arrs
continuationImportant:
The list of continuations is NOT implemented as a type sequence but simply as a Vector[Any => Eff[R, Any]]
This means that various .asInstanceOf
are present in the implementation and could lead
to burns and severe harm. Use with caution!
http://okmij.org/ftp/Haskell/extensible/more.pdf
one effect, basically a type constructor
Effects is a type level representing a list of effects which might take place in a computation
Effects is a type level representing a list of effects which might take place in a computation
Note that each "effect" is a type constructor
Append an effect at the beginning of a list of effects
Effect for computation which can fail and return a Throwable, or just stop with a failure
Effect for computation which can fail and return a Throwable, or just stop with a failure
This effect is a mix of Eval and Xor in the sense that every computation passed to this effect (with the ok method) is considered "impure" or "faulty" by default.
The type F is used to represent the failure type.
Effect for delayed computations
Effect for delayed computations
uses cats.Eval as a supporting data structure
support trait for folding values while possibly keeping some internal state
Effect for Future computations
union is a disjoint union of effects returning a value of type X (not specified)
union is a disjoint union of effects returning a value of type X (not specified)
Support methods to create an interpreter (or "effect handlers") for a given Eff[M |: R, A].
Support methods to create an interpreter (or "effect handlers") for a given Eff[M |: R, A]. The aim being to "consume" just that effect and produce a value of type B with possibly other effects: Eff[R, B]
Those methods guarantee a stack-safe behaviour when running on a large list of effects (in a list.traverseU(f) for example).
There are 3 different types of supported interpreters:
This interpreter is used to handle effects which either return a value X from M[X] or stops with Eff[R, B] See an example of such an interpreter in Eval where we just evaluate a computation X for each Eval[X].
2. interpretState + StateRecurse
This interpreter is used to handle effects which either return a value X from M[X] or stops with Eff[R, B]
3. interpretLoop + Loop
The most generic kind of interpreter where we can even recurse in the case of Pure(a) (See ListEffect for such a use)
Trait for polymorphic recursion into Eff[?, A]
Trait for polymorphic recursion into Eff[?, A]
The idea is to deal with one effect at the time:
Effect for computations possibly returning several values
Member typeclass for effects belonging to a stack of effects R
Member typeclass for effects belonging to a stack of effects R
If T is a member of R then we can:
- create a Union of effects from a single effect with "inject" - extract an effect value from a union if there is such an effect in the stack
Nil case for the list of effects
Effect for optional computations
Effect for computations depending on an environment.
Effect for computations depending on an environment.
The inside datatype for this effect is cats.data.Reader
Effect for passing state along computations
Effect for passing state along computations
Internally backed up by cats.data.State
Open union of effects
Open union of effects
They are modelled as a list of
UnionNext(UnionNext(...(UnionNow(M[X])))
where M[X] is an effect. The depth of the nesting in an Union value corresponds to the place of the effect in a type E1 |: E2 |: E3 |: .. |: NoEffect
Effect for computation which can fail but will accumulate errors
Effect for computation which can fail but will accumulate errors
The runValidate interpreter just collects the messages and returns them at the end
Effect for logging values alongside computations
Effect for logging values alongside computations
Compared to traditional Writer monad which accumulates values by default this effect can be interpreted in different ways:
Effect for computation which can fail
Aliases for declaring effects with the following syntax
Aliases for declaring effects with the following syntax
A |: B |: C |: NoEffect
Simple instantiation of the ErrorEffect trait with String as a Failure type
create union objects