I always found that I have a difficulty to underst...
# getting-started
a
I always found that I have a difficulty to understand the documentation from Kotlin website.
inline fun <T, R> with(receiver: T, block: T.() -> R): R (source)
I don't really understand what is this trying to explain although I have read through the explanation. I know
T
might stands for
Type
but what does
R
stands for? Run? The
receiver
is the argument we pass into it? What is
block
?
R
i would assume it is the result then. Am I right?
d
Both
T
and
R
are type variables: https://kotlinlang.org/docs/reference/generics.html The names do not really mean anything in this context, usually people name their first type parameter
T
and then continue down the alphabet.
This is an arguably non-optimal naming scheme though
l
Would that be more clear for you?
inline fun <TParam, TResult> with(receiver: TParam, block: TParam.() -> TResult): TResult
👍 3
a
If I read through the documentation, how to interpret it?
Copy code
inline fun functionName<T, R>(parameter: T) -> TResult
Something similar like this?
l
it has nothing to do how the documentation is written and your example won't even compile read about generics first like @diesieben07 mentioned https://kotlinlang.org/docs/reference/generics.html