Open ur-liza opened 1 year ago
Man that drives me nuts, dear @AndroidDevelopers please add a green hint box to the tutorial explaining the circumstance. It gets even crazier when you exchange the treatFunction within the repeat with the trickOrTreat. In that case it prints "5 quarters" four times but not "Have a treat!".
So why both 5 quarters
and Have a treat
aren't repeated 5 times ? Did you find the explanation @NemesisJWD and @ur-liza ?
Thank you.
Ok, got the answer on the AndroidDev discord.
5 quarters
is printed only once because it is executed only once (when treatFunction
is affected by trickOrTreat(false) { "$it quarters" }
) ! Then, note that the trickOrTreat
function only returns trick
or treat
. In our case, treatFunction
is equal to treat
function only ! So when we repeat treatFunction
4 times, it only calls treat
function 4 times (and not at all the whole trickOrTreat(false) { "$it quarters" }
) !!
URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-compose-function-types-and-lambda?hl=en#5
In which task and step of the codelab can this issue be found? "Run your code. The "Have a treat" string should print four times."
Describe the problem The problem is that there is no explanation why
5 quarters
is printed out only once, instead of four times.Steps to reproduce?
Versions Android Studio version: API version of the emulator:
Additional information Include screenshots if they would be useful in clarifying the problem.