Reader

sealed interface Reader<out R> : Effect<R> (source)

A read-only environment: ask reads it, runReader supplies it, local overrides it for one sub-program.

The environment type is erased: Reader.Ask is declared over Any?, so ask casts to the type its caller names and no handler can check it, and a handler stack carries one environment type (a second type needs a second effect class). Call sites often need the type argument spelled out, as in ask<String>().

local asks downstream once for the current value, then answers every Ask inside the sub-program itself with the transformed value, so those Asks never reach the downstream handler; Asks outside the sub-program still get the downstream answer. Both steps are a plain flatMap and a direct resume, so local also works under a multi-shot handler such as collectAll.

Inheritors

Types

Link copied to clipboard
data object Ask : Reader<Any?>

Read the environment.