turbolift

package turbolift

Members list

Type members

Classlikes

sealed abstract class Computation[+A, -U]

Monad parametrized by a set of requested effect. Use the !! infix type alias instead.

Monad parametrized by a set of requested effect. Use the !! infix type alias instead.

Type-level set of effects is modelled with intersection types. Type Any means empty set.

type MyComputationType1 = String !! (MyState & MyError)
type MyComputationType2 = String !! Any

Type parameters

A

Result of the computation

U

Type-level set of effects requested by this computation.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Computation

Use the !! alias to access methods of this companion object.

Use the !! alias to access methods of this companion object.

Example:

import turbolift.!!

val myComputation: Int !! Any = !!.pure(42)

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
trait Effect[Z <: Signature] extends CanPerform[Z]

Base trait for any user-defined effect.

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

Companion
object
Supertypes
trait CanPerform[Z]
trait Signature
class Object
trait Matchable
class Any
Known subtypes
trait Choice
object Each.type
object Console.type
trait ErrorEffect[E, E1]
trait Error[E]
trait ErrorG[M, K, V]
trait ErrorGK[M, K, F, V]
trait ErrorK[F, E]
trait RandomEffect
object Random.type
trait Reader[R]
trait State[S]
trait WriterEffect[W, W1]
trait Writer[W]
trait WriterG[M, K, V]
trait WriterGK[M, K, F, V]
trait WriterK[F, W]
Show all
Self type
Z
object Effect

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Effect.type

Orphaned extensions.

Orphaned extensions.

Extensions of standard library types, like Iterable, Iterator, etc.

Usage: just import them all.

import turbolift.Extensions._

Attributes

Supertypes
class Object
trait Matchable
class Any
Show all
Self type
Extensions.type
sealed trait Handler[From[_], To[_], Elim, Intro]

Used to delimit scope of effect(s).

Used to delimit scope of effect(s).

Handler transforms a Computation, by discharging some or all of its requested effects, and (optionally) introducing handlers own dependencies to it (set of effects used to create the handler).

val myComputation2 = myComputation1.handleWith(myHandler)

Handlers can be obtained by:

  • implementing an Interpreter for an Effect, and then calling toHandler method on it.
  • transforming a preexisting handler, e.g. val myHandler2 = myHandler1.map(...)
  • composing 2 preexisting handlers, e.g. val myHandler3 = myHandler1 &&&! myHandler2

Compositon of 2 handlers is always sequential: the operands are applied in left to right order.

The From[_] type parameter can only have 2 forms:

  • type-level identity function: [X] =>> X
  • type-level constant function: [_] =>> C

The To[_] type parameter has no restrictions, but often happens to be identity.

Type parameters

Elim

Type-level set of effects, that this handler eliminates from the computation.

From

Type constructor, indicating what computation's result types can be accepted by this handler as input.

Intro

Type-level set of effects, that this handler introduces into the computation. This is often an empty set, expressed as Any.

To

Type constructor (e.g. Option[_]), in which the computation's result is wrapped, after application of this handler.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Handler

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Handler.type
trait Signature extends AnyRef

Base trait for any user-defined effect signature. Used to define custom Algebra/Service/DSL.

Base trait for any user-defined effect signature. Used to define custom Algebra/Service/DSL.

Example:

import turbolift.Signature

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

See Defining your own effects and handlers.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Choice
object Each.type
object Console.type
trait ErrorSignature[E, E1]
trait ErrorEffect[E, E1]
trait Error[E]
trait ErrorG[M, K, V]
trait ErrorGK[M, K, F, V]
trait ErrorK[F, E]
trait IO
object IO.type
trait RandomEffect
object Random.type
trait ReaderSignature[R]
trait Reader[R]
trait StateSignature[S]
trait State[S]
trait WriterSignature[W, W1]
trait WriterEffect[W, W1]
trait Writer[W]
trait WriterG[M, K, V]
trait WriterGK[M, K, F, V]
trait WriterK[F, W]
trait CanPerform[Z]
trait Effect[Z]
trait Interpreter
class Proxy[Fx]
class Proxy[Fx]
class Stateful[F, G, Fx]
class Stateful[F, G, Fx]
class FromConst[C, G, Fx]
class Free[C, G]
class ToConst[C, D, Fx]
class Free[C, D]
class FromId[G, Fx]
class Free[G]
class ToConst[D, Fx]
class Free[D]
class ToId[Fx]
class Free
class Stateless[F, G, Fx]
class Stateless[F, G, Fx]
class FromConst[C, G, Fx]
class Free[C, G]
class ToConst[C, D, Fx]
class Free[C, D]
class FromId[G, Fx]
class Free[G]
class ToConst[D, Fx]
class Free[D]
class ToId[Fx]
class Free
Show all

Types

type !![+A, -U] = Computation[A, U]

Alias for Computation type. Meant to be used in infix form.

Alias for Computation type. Meant to be used in infix form.

Attributes

Value members

Concrete methods

def !!: Computation.type

Alias for Computation companion object.

Alias for Computation companion object.

Attributes