Kotlin let function

This post was originally posted at https://agrawalsuneet.github.io/blogs/kotlin-let-function/ and reposted on Medium on 26th Feb 2020.
  • let
  • with
  • run
  • apply
  • also
* Calls the specified function [block]
* with `this` value as its argument
* and returns its result.
public inline fun <T, R> T.let(block: (T) -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
return block(this)
  1. The return type of the let function is nothing but the last expression we returned from our passed lambda parameter.
  2. Since its an extension function to the Template class, it can be called on any object.

Please continue reading at https://agrawalsuneet.github.io/blogs/kotlin-let-function/




Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store