The Interpret trait provides method to interpret (or "handle") effects.
An interpreter generally handles a given effect M and a value Eff[R, A] where M is a member of R.
The most general way of interpreting an effect is to implement the Interpreter trait for that effect and use the runInterpreter method. With the Interpreter
trait you need to define:
- what to do with pure values
- what to do with an effect
- what to do with a list of effects (the "applicative" case)
- what to do with a "last" effect, in case of having side-effects to finalize resources (see the SafeEffect)
For each of those methods you get access to a continuation which you may or may not invoke to create the next effect in a sequence of effects. For example with the EitherEffect once you arrive on a Left value you don't trigger the continuation because there is no value to trigger it with.
There are also easier ways to define interpreters. The recurse
method and the Recurser
trait define:
onPure(a: A): B
: how to map a pure value A to the result BonEffect[X](mx: M[X]): X Either Eff[R, B]
: either extract a value from the effect or return another effectonApplicative[X](tx: T[M[X]]): T[X] Either M[T[X]]
: either extract individual values from each effect or "sequence" the effect
Even simpler, the Translate
trait does a translation from an effect M[X]
to other effects in the stack.
There are also a few intercept
methods to use an effect but still leave it in the stack
Attributes
- Companion
- object
- Source
- Interpret.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes