I don't know if `inikio` is exactly part of arrow ...
# arrow
c
I don't know if
inikio
is exactly part of arrow (I can delete if this is an inappropriate venue), but my question should be generic to any tagless-style interpreter -- is there a way to compose interpreters when using the
suspend
approach? I might also be misunderstanding the "right" way to do this. Using the
inikio
example:
Copy code
tailrec fun <A> Casino<A>.execute(): A =
  when(this) {
    is Done -> result
    is FlipCoin -> next(Random.nextFlipOutcome()).execute()
  }
What if I e.g. wanted to log something whenever
FlipCoin
is interpreted?
a
the easiest way is to make whatever other interpreter you need into the rewceiver
Copy code
tailrec fun <A> OtherInterpreter.execute(casino: Casino<A>): A = when (this) {
  is Done -> result
  is FlipCoin -> {
    val outcome = Random.nextFlipOutcome()
    operationFromOtherInterpreter(outcome)
    execute(next(outcome))
  }
}
c
Thank you! Is there an equivalent to something like
Coproduct
, where each interpreter doesn't have to be aware of the others?
a
that depends on your use case with the advent of context receivers you would be able to write
context(Casino, OtherTagless) fun doSomething(): A
and then interpret as you wish
c
oh yeah, great point. thanks again! (and thanks for the library and walkthrough docs!)