https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Alex

10/02/2021, 5:46 PM
Hi All, i'm still learning Kotlin and i'm currently learning how to use scope functions and would like to understand what the following mean for points 1 and 2
inline fun <T, R> T.let(*block*: (T) -> R): R
1) <T, R> T what does the extra T outside the <> mean
2) What does R mean
k

Kirill Grouchnikov

10/02/2021, 5:55 PM
j

Joffrey

10/02/2021, 5:56 PM
There are many concepts packed in the same function here, so it's normal to be a bit confused.
<T,R>
and the following
T
are 2 separate parts of the function definition. • The part between <> declares the type parameters of the function (because the function is generic). • The following
T
is the receiver of the function, because
let
is an _extension_ function. • The
R
is a generic type used as the return type of the function and also as the return type of the
block
argument (which is also a function)
😄 1
a

Alex

10/02/2021, 6:11 PM
Thank you so much @Joffrey and @Kirill Grouchnikov 😄👍💯