https://kotlinlang.org logo
#arrow
Title
# arrow
j

Jörg Winter

08/23/2022, 11:19 AM
There are 2 repos in arrow-kt "arrow-inject" and "arrow-proofs" From the commits I guess that arrow-proofs is the way to go in the future, right ? ...so that instead of this
Copy code
fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
   with(bookInput) {
      withParsedBook().fold(....)
...we can have this ?
Copy code
fun createUser(bookInput: BookInput): ResponseEntity<ParsedBookResponse> =
      withParsedBook().fold(....)
...by annotation + compiler plugin or Kotlin context receiver ? Currently I have this function:
Copy code
context(BookInput)
fun withParsedBook(): Validated<NonEmptyList<String>, ParsedBook> {....}
from this example I guess we still need that context<MyDependency> instead of with(MyDependency) ?
r

raulraja

08/23/2022, 12:56 PM
Hi @Jörg Winter, Arrow proofs is the current ongoing effort over a compiler plugin based on the new compiler FIR and k2. FIR is still not stable but when it comes out it will work on the IDE too. Proofs will focus on context receiver resolution. For example https://github.com/arrow-kt/arrow-proofs/tree/main/arrow-inject-compiler-plugin/src/testData/box/context-receivers Instead of
with
and a lambda you will be able to bring
@Provider
into the scope using
context<A, B, C, ...>
. for example:
j

Jörg Winter

08/23/2022, 1:01 PM
In that example, if f() had the dependencies as parameters, would they be injected into another receiving function that is called inside f() ?
r

raulraja

08/23/2022, 1:13 PM
They are exclusively injected when you summon their types with
context<A, B, ...>
. If you had declared instead those as context parameters to the function then when you call the function you have to summon them with
context
. It's possible to make it all implicit and just allow the call to resolve them magically based on what is missing, but we have not made a decision yet on whether that is a good idea or
context<A, B..
should be explicit.
63 Views