google-developer-training / basic-android-kotlin-compose-training-dice-roller

Apache License 2.0
57 stars 49 forks source link

Use function types and lambda expressions in Kotlin: Android Basics with Compose #136

Open om-nom-nomm opened 6 months ago

om-nom-nomm commented 6 months ago

URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-compose-function-types-and-lambda?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-2-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-function-types-and-lambda#5

In which task and step of the codelab can this issue be found? 6. Use the repeat() function, the last step

Describe the problem Hello. I'm not sure if there's a problem, but I'm pretty confused.

On the last step of [6. Use the repeat() function] it's offered to move the call of the treatFunction() into the repeat() function's lambda expression: repeat(4) { treatFunction() }

This will result in the following output: 5 quarters Have a treat! Have a treat! Have a treat! Have a treat! No treats! // the result of trickFunction() call, it's not interesting right now

At the same time one call of the treatFunction() results in the next output: 5 quarters Have a treat!

Why only "Have a treat!" is repeated? Looks like 'extraTreat' lamda expression is lost after the 1st repeat() iteration. Why so?

Steps to reproduce?

  1. Go to... Kotlin playground on the link: https://pl.kotl.in/2S46SnuP3
  2. Click on... Run button in the top right corner
  3. See error... The result is: 5 quarters Have a treat! Have a treat! Have a treat! Have a treat! No treats!

My expectation the result is to be: 5 quarters Have a treat! 5 quarters Have a treat! 5 quarters Have a treat! 5 quarters Have a treat! No treats!

Versions Android Studio version: API version of the emulator:

Additional information Include screenshots if they would be useful in clarifying the problem. Please follow the link on Kotlin playground: https://pl.kotl.in/2S46SnuP3

om-nom-nomm commented 6 months ago

Sorry, I've seen that I duplicated the issue [#99] only after I'd posted mine.