CLOVIS
04/14/2020, 3:17 PMval fm = ::f.memoize()
The only way I can think of to implement this in Kotlin would be something akin to:
fun Function.memoize(): Function { ... }
However, doing this will remove static typing of the function parameters, which is ‘un-kotliny'.
A solution could be to add a new type of generics, Function argument generics, which could look something like:
fun <T...> Function<T>.memoize(): Function<T>
and would mean something like ‘I return a function that takes the same parameters as my receiver did'.
Now my question is, the Arrow team probably thought of something like that at some point, so did you find a solution for it, or another way to achieve something similar? I feel like it could add a lot of flexibility into the language. How did you implement things that look like this?
From my understanding the only way to have something similar would be to have a compiler plugin that would automatically generate all versions up to 22:
fun Function2<A, B, C>.memoize(): Function2<A, B, C>
fun Function3<A, B, C, D>.memoize(): Function3<A, B, C, D>
...