turbolift.Effect
See theEffect companion object
trait Effect[Z <: Signature] extends CanPerform[Z]
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
// 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
Members list
In this article