0Pricing
Kotlin Academy · Lesson

Choosing the Right One

When to use each.

Choosing a Scope Function

With five scope functions available, picking the right one comes down to two questions:

  • How is the object referenced: this or it?
  • What is returned: the lambda result or the object?

The Decision Table

Here is the full picture:

  • let uses it, returns lambda result.
  • run uses this, returns lambda result.
  • with uses this (arg), returns lambda result.
  • apply uses this, returns object.
  • also uses it, returns object.

All lessons in this course

  1. let and run
  2. apply and also
  3. with
  4. Choosing the Right One
← Back to Kotlin Academy