bynk.effect.cross_context_in_pure_context
Error A cross-context call was made in a pure context.
A call to a service in a consumed context is an effect, as a capability call is, so it is only allowed in a body that is itself effectful. A handler is effectful, but a lambda inside it is a body of its own, and a service call alone does not make it effectful. Make the call in the handler body, bind it with <-, and use the result in the lambda.
Example
on call() -> Effect[Int] by Caller { let f = (n: Int) => pay.charge(n) // ✗ a service call in a pure lambda Effect.pure(1)}
on call() -> Effect[Int] by Caller { let paid <- pay.charge(5) // ✓ the handler makes the call let f = (n: Int) => n + paid Effect.pure(f(1))}In the Book
See also
- Every code in its category, Effects, on the diagnostic index.
bynk explain bynk.effect.cross_context_in_pure_contextshows the same from the installed toolchain, without a network.