What are scope functions in Kotlin?

Technology CommunityCategory: KotlinWhat are scope functions in Kotlin?
VietMX Staff asked 3 years ago

The Kotlin standard library contains several functions whose sole purpose is to execute a block of code within the context of an object. When you call such a function on an object with a lambda expression provided, it forms a temporary scope. In this scope, you can access the object without its name. Such functions are called scope functions.

There are five of them:

  • let,
  • run,
  • with,
  • apply,
  • also.