Handler

sealed trait Handler[Result[_], Elim, Intro]

Handler is an object used to transform a Computation, by discharging some or all of its requested effects.

For example, having:

val myComputation2 = myComputation1.handleWith(myHandler)

...then, myComputation2 will have the type of myComputation1, modified as follows:

  • Elim effects will be removed from the set of requested effects.
  • Intro effects (if any) will be inserted to the set of requested effects.
  • The result type A, will be transformed into Result[A].

Handlers can be obtained in 3 ways:

  • By implementing an Interpreter for an Effect, and then transforming it into a Handler.
  • By transforming a preexisting handler, e.g: val myHandler2 = myHandler1.map(...)
  • By composing 2 preexisting handlers, e.g: val myHandler3 = myHandler1 &&&! myHandler2
Type parameters:
Elim

Type-level set of effects, expressed as an intersection type, that this handler eliminates from the computation.

Intro

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

Result

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

Companion:
object
class Object
trait Matchable
class Any

Type members

Classlikes

final class HandleApply[V]
class PartiallyProvideWithApply[Remains >: Intro]

Value members

Concrete methods

final def &&&![ThatResult[_], ThatElim, ThatIntro](that: Handler[ThatResult, ThatElim, ThatIntro]): Handler[[X] =>> ThatResult[Result[X]], Elim & ThatElim, Intro & ThatIntro]

Alias for composeWith.

Alias for composeWith.

final def composeWith[ThatResult[_], ThatElim, ThatIntro](that: Handler[ThatResult, ThatElim, ThatIntro]): Handler[[X] =>> ThatResult[Result[X]], Elim & ThatElim, Intro & ThatIntro]

Composes 2 independent handlers sequentially. This handler is applied first.

Composes 2 independent handlers sequentially. This handler is applied first.

Independence of handlers means, that effects eliminated by one of the handlers, do not overlap with effects introduced by the other.

Independence of 2 handlers guarantees, that it is also valid to compose them in the opposite order. However, nesting order of their Result[_]s would also be reversed.

final def flatMap[NewResult[_], V](f: [X] => (x$1: Result[X]) => Computation[NewResult[X], V]): Handler[NewResult, Elim, Intro & V]

Like map, but the post-processing of Result[_] can also introduce effects.

Like map, but the post-processing of Result[_] can also introduce effects.

Those effects are then absorbed by the new handler into the effects it introduces.

final def flatTap[V](f: [X] => (x$1: Result[X]) => Computation[Unit, V]): Handler[Result, Elim, Intro & V]

Like flatMap, but the post-processing is executed for its effects only.

Like flatMap, but the post-processing is executed for its effects only.

This handler's Result[_] remains unchanged.

final def handle[V]: HandleApply[V]

Applies this handler to given computation.

Applies this handler to given computation.

Equivalent of Computation's handleWith(this)

final def map[NewResult[_]](f: [X] => (x$1: Result[X]) => NewResult[X]): Handler[NewResult, Elim, Intro]

Composes this handler with a post-processing function, applied to this handler's Result[_].

Composes this handler with a post-processing function, applied to this handler's Result[_].

a.k.a Natural Transformation.

final def partiallyProvideWith[Remains >: Intro]: PartiallyProvideWithApply[Remains]

Composes 2 partially dependent handlers sequentially. This handler is applied first.

Composes 2 partially dependent handlers sequentially. This handler is applied first.

Assumes that some of effects introduced by this handler, are eliminated by that handler.

final def provideWith[ThatResult[_], ThatIntro](that: Handler[ThatResult, Intro, ThatIntro]): Handler[[X] =>> ThatResult[Result[X]], Elim, ThatIntro]

Composes 2 fully dependent handlers sequentially. This handler is applied first.

Composes 2 fully dependent handlers sequentially. This handler is applied first.

Assumes that all effects introduced by this handler, are eliminated by that handler.

final def run[A](comp: Computation[A, Elim])(implicit ev: Intro =:= Any): Result[A]

Runs given computation, provided that all of its effects can be discharged by this handler.

Runs given computation, provided that all of its effects can be discharged by this handler.

Equivalent of Computation's handleWith(this) followed by run

final def void: Handler[[X] =>> Unit, Elim, Intro]

Maps Result[_] to Unit.

Maps Result[_] to Unit.

Inherited methods

def ***!: Handler[Tuple2, L & L2, N & N2]
Extension method from Handler
Inherited from:
HandlerExtensions
def dropState: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def eval: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def exec: Const[S, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def flatMapState: Handler[Tuple2, L, N & U]
Extension method from Handler
Inherited from:
HandlerExtensions
def flatTapState: Handler[Tuple2, L, N & U]
Extension method from Handler
Inherited from:
HandlerExtensions
def getOrDie: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def getOrDie: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def getOrElse: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def getOrElse: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def justState: Const[S, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def mapLeft: Handler[[_] =>> Either[E2, _$11], L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def mapState: Handler[Tuple2, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def toEither: Handler[[_] =>> Either[E, _$8], L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def toOption: Handler[Option, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def toTry: Handler[Try, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def toTry: Handler[Try, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def toVector: Handler[Vector, L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
def unsafeGet: Id[L, N]
Extension method from Handler
Inherited from:
HandlerExtensions
@targetName("flattenEithers")
def |||!: Handler[[_] =>> Either[E | E2, _$13], L & L2, N & N2]
Extension method from Handler
Inherited from:
HandlerExtensions
@targetName("flattenOptions")
def |||!: Handler[Option, L & L2, N & N2]
Extension method from Handler
Inherited from:
HandlerExtensions