<@U0ANSGGVC> &gt; It seems, what I need is a spec...
# announcements
It seems, what I need is a special function type with the signature
operator fun <T> invoke(p1: T): R<T>
. I can write that interface down myself, but that I wouldn't be able to use lambda syntax (without writing down a factory function).
however isn't a proper type
Looks like what you want are higher kinded types, which Kotlin does not support. There are ways to approximate them with some level of type safety (at least without resorting to
) but it's a little involved. What you can do is wrapping instances of type constructors like your Future in a "kinded context" (an interface basically) by flattening your types.
Kind1<R, T>
R<S, T>
Kind2<R, S, T>
and so forth. The trick is then to "instantiate"
by using an inner class:
Copy code
class FutureKind<T>(val future: Future<T>) : Kind1<FutureKind.R, T> {
    class R
any code that acts on type constructors can then be expressed by using an appropriate instantiation of
. You can use type aliases in Kotlin 1.1 to make this a bit more readable. There will still be occasions where you'll have to downcast a
though to access the wrapped value, but you can make this relatively safe by having an extension method that performs the cast on a configuration of the specific types. This cast would only fail if you had 2 different implementations for future, which is quite unlikely. But yeah, it's a lot of boilerplate, might not be worth it in your case...