0

In which use cases does one use the other similar scope functions instead of let, like run or also, or even with?

5
  • There's this nice table in the documentation that you can easily find on Google. What don't you understand from there? Commented Jun 14, 2021 at 2:24
  • @Sweeper thanks for the link, though I have made the question more focused now and I hope specific context from the link can be used here to answer it Commented Jun 14, 2021 at 3:46
  • There are about 10000 blog posts about this on Medium. Seems like every other newcomer to Kotlin wants to rewrite that same page from the documentation. Anyway, your update to the question doesn't help. That documentation page linked above gives examples of how each of them should be used. What about that list do you not understand specifically? All the scope functions are similar to each other in different ways. Commented Jun 14, 2021 at 3:59
  • 2
    @Tenfour04 This is exactly what is confusing - All the scope functions are similar to each other in different ways. Also this question is specifically about alternatives to let for general use cases like executing some logic on non-null objects and such. Finally IMO, the new-comers might find this info useful. Commented Jun 14, 2021 at 4:32
  • 1
    See also Example of when should we use run, let, apply, also and with on Kotlin. Commented Jun 14, 2021 at 4:45

1 Answer 1

2

There is no right answer. It's a judgement call. Choose the one that best fits your situation whether you want this or it available internally, and whether you want to return the lambda result or the value of the object you called the scope function on.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer Adam. I think both the points bring clarity: 1. whether you want this or it available internally 2. whether you want to return the lambda result or the value of the object

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.