Effect

turbolift.Effect
See theEffect companion object
trait Effect[Z <: Signature]

Base trait for any user-defined effect.

Instances of Effect are used:

  • To establish unique identity of the effect, both in type and value space.
  • By effect users: to invoke operations of the effect.
  • By creators of effect handlers: to access base classes needed for implementing interpreters for this effect.

Example:

import turbolift.{!!, Signature, Effect}}

// Signature:
trait GoogleSignature extends Signature:
 def countPicturesOf(topic: String): Int !! ThisEffect

// Boilerplate:
trait Google extends Effect[GoogleSignature] with GoogleSignature:
 final override def countPicturesOf(topic: String) = perform(_.countPicturesOf(topic))

// Instantiaton establishes the identity:
case object MyGoogle extends Google
type MyGoogle = MyGoogle.type // optional

// Alternative way to instantiate the effect, using macro to skip the boilerplate:
// (generates the `trait Google` above)
val MyGoogle = Effect.boilerplate[GoogleSignature]
type MyGoogle = MyGoogle.type // optional

// Invoking operations:
val program: Int !! MyGoogle = MyGoogle.countPicturesOf("cat")

For details, see Defining your own effects and handlers.

Type parameters

Z

The Signature of this effect.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait ChoiceEffect
object Choice
object Each
object Console
trait Cont[R]
trait CoroutineEffect[I, O, R]
trait ErrorEffectExt[E, E1]
trait ErrorEffect[E]
trait ErrorEffectG[M, K, V]
trait ErrorEffectGK[M, K, F, V]
trait ErrorEffectK[F, E]
trait LazyMemoizerEffect[K, V]
trait MaybeEffect
object Broken
object Maybe
trait MemoizerEffect[K, V]
trait RandomEffect
object Random
trait ReaderEffect[R]
trait ResourceEffect[U]
object ResourceIO
trait StateEffect[S]
trait WriterEffectExt[W, W1]
trait WriterEffect[W]
trait WriterEffectG[M, K, V]
trait WriterEffectGK[M, K, F, V]
trait WriterEffectK[F, W]
Show all
Self type
Z

Members list

Type members

Types

final override type ThisEffect = this.type
type ThisSignature[U] = Z & Signature { type ThisEffect = U; }

API for defining custom effects.

API for defining custom effects.

Attributes

Value members

Concrete methods

final def &![Fx2 <: Signature](fx2: Fx2): Combine2[this.type, fx2.type]

API for defining custom handlers.

API for defining custom handlers.

Combines with another Effect instance, for the purpose of sharing an Interpreter.

Example of application: implement RWS-alike handler for Reader &! Writer &! State composition of effects.

Attributes

final inline def perform[A, U <: ThisEffect](inline f: (ThisSignature[U]) => Computation[A, U]): Computation[A, U]

API for defining custom effects.

API for defining custom effects.

Embeds an invocation of this Signature's method into the Computation monad. This provides mechanism for separation between syntax an semantics of effects.

Attributes

final def performNoInline[A, U <: ThisEffect](f: (ThisSignature[U]) => Computation[A, U]): Computation[A, U]

API for defining custom effects.

API for defining custom effects.

Attributes

Concrete fields

val impl: Impl[Effect[Z]]

API for defining custom handlers.

API for defining custom handlers.

Helper object providing type definitions to be used for implementing Interpreters for this effect.

Attributes

Exports

Defined exports

final type ThisHandler = [F[_], G[_], N] =>> impl.ThisHandler[F, G, N]
Exported from Impl