Interpret

org.atnos.eff.Interpret
See theInterpret companion object
trait Interpret

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 B
  • onEffect[X](mx: M[X]): X Either Eff[R, B]: either extract a value from the effect or return another effect
  • onApplicative[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 Object
trait Matchable
class Any
Known subtypes
object Interpret.type
object interpret.type

Members list

Type members

Types

type of[F[_], G[_]] = { type l = [A] =>> F[G[A]]; }

Attributes

Source
Interpret.scala

Value members

Concrete methods

def augment[R, T[_], O[_], A](eff: Eff[R, A])(w: Augment[T, O])(implicit memberT: MemberInOut[T, R], memberO: MemberIn[O, R]): Eff[R, A]

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)

Attributes

Source
Interpret.scala
def intercept[R, T[_], A, B](e: Eff[R, A])(interpreter: Interpreter[T, R, A, B])(implicit m: MemberInOut[T, R]): Eff[R, B]

Attributes

Source
Interpret.scala
def interceptNat[R, T[_], A](effect: Eff[R, A])(nat: FunctionK[T, T])(implicit m: MemberInOut[T, R]): Eff[R, A]

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

Attributes

Source
Interpret.scala
def interceptNatM[R, M[_], F[_], A](effect: Eff[R, A], nat: FunctionK[M, <none>])(implicit m: MemberInOut[M, R], FT: Traverse[F], FM: Monad[F]): Eff[R, F[A]]

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

Attributes

Source
Interpret.scala
def interpretUnsafe[R, U, T[_], A](effect: Eff[R, A])(sideEffect: SideEffect[T])(implicit m: Aux[T, R, U]): Eff[U, A]

interpret an effect by running side-effects

interpret an effect by running side-effects

Attributes

Source
Interpret.scala
def recurse[R, U, T[_], A, B](e: Eff[R, A])(recurser: Recurser[T, U, A, B])(implicit m: Aux[T, R, U]): Eff[U, B]

Interpret an effect with a Recurser

Interpret an effect with a Recurser

Attributes

Source
Interpret.scala
def runInterpreter[R, U, T[_], A, B](e: Eff[R, A])(interpreter: Interpreter[T, U, A, B])(implicit m: Aux[T, R, U]): Eff[U, B]

Attributes

Source
Interpret.scala
def trace[R, T[_], A](eff: Eff[R, A])(implicit memberT: MemberInOut[T, R], memberW: MemberInOut[[_] =>> Writer[T[_], _$26], R]): Eff[R, A]

For a single effect T log every value of that effect

For a single effect T log every value of that effect

Attributes

Source
Interpret.scala
def transform[SR, BR, U1, U2, TS[_], TB[_], A](effect: Eff[SR, A], nat: FunctionK[TS, TB])(implicit sr: Aux[TS, SR, U1], br: Aux[TB, BR, U2], into: IntoPoly[U1, U2]): Eff[BR, A]

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

Attributes

Source
Interpret.scala
def translate[R, U, T[_], A](effect: Eff[R, A])(tr: Translate[T, U])(implicit m: Aux[T, R, U]): Eff[U, A]

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

Attributes

Source
Interpret.scala
def translateInto[R, T[_], U, A](effect: Eff[R, A])(tr: Translate[T, U])(implicit t: MemberInOut[T, R], into: IntoPoly[R, U]): Eff[U, A]

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

Attributes

Source
Interpret.scala
def translateNat[R, U, T[_], A](effects: Eff[R, A])(nat: FunctionK[T, [_] =>> Eff[U, _$8]])(implicit m: Aux[T, R, U]): Eff[U, A]

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

Attributes

Source
Interpret.scala
def write[R, T[_], O, A](eff: Eff[R, A])(w: Write[T, O])(implicit memberT: MemberInOut[T, R], memberW: MemberIn[[_] =>> Writer[O, _$22], R]): Eff[R, A]

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

Attributes

Source
Interpret.scala