Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
om-nom-nomm opened this issue May 4, 2024 · 1 comment

Comments

@om-nom-nomm
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant