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 intoResult[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
Type members
Value members
Concrete methods
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.
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.
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.
Applies this handler to given computation.
Applies this handler to given computation.
Equivalent of Computation's handleWith(this)
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.
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.
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.
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