Is there a way to write a member/method reference to return the object itself in Kotlin? That is to say, it can simplify and replace the following lambda:
{ it }
Is there a way to write a member/method reference to return the object itself in Kotlin? That is to say, it can simplify and replace the following lambda:
{ it }
There isn't a built in way as far as I know. Best you could do is write a function that does this once, and then refer to that when you need it, e.g.
inline fun <T> identity(t: T) = t
And then usage like so:
"foo".let(::identity) // still "foo"