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
- Companion:
- object
- Source:
- Interpret.scala
Type members
Types
Value members
Concrete methods
Interpret the effect T with a side-effect O (see the write method below)
Interpret the effect T with a side-effect O (see the write method below)
- Source:
- Interpret.scala
- Source:
- Interpret.scala
Intercept the values for one effect and transform them into other values for the same effect
Intercept the values for one effect and transform them into other values for the same effect
- Source:
- Interpret.scala
Intercept the values for one effect, emitting new values for the same effect inside a monad which is interleaved in
Intercept the values for one effect, emitting new values for the same effect inside a monad which is interleaved in
- Source:
- Interpret.scala
interpret an effect by running side-effects
interpret an effect by running side-effects
- Source:
- Interpret.scala
- Source:
- Interpret.scala
For a single effect T log every value of that effect
For a single effect T log every value of that effect
- Source:
- Interpret.scala
transform an effect into another one using a natural transformation, leaving the rest of the stack untouched
transform an effect into another one using a natural transformation, leaving the rest of the stack untouched
- Source:
- Interpret.scala
Translate one effect of the stack into some of the other effects in the stack
Translate one effect of the stack into some of the other effects in the stack
- Source:
- Interpret.scala
Translate one effect of the stack into other effects in a larger stack
Translate one effect of the stack into other effects in a larger stack
- Source:
- Interpret.scala
Translate one effect of the stack into some of the other effects in the stack Using a natural transformation
Translate one effect of the stack into some of the other effects in the stack Using a natural transformation
- Source:
- Interpret.scala
For each effect T add some "log statements" O using the Writer effect
For each effect T add some "log statements" O using the Writer effect
- Source:
- Interpret.scala