https://kotlinlang.org logo
Title
a

APXEOLOG

12/03/2018, 4:54 PM
Yes, but i wondered is there is a way to create generic function for this instead of adding flags for every place like this
d

diesieben07

12/03/2018, 4:59 PM
Maybe what you want is a lazy property?
val x: String by lazy {
    // executed only on first access
    expensiveFunction() 
}
a

APXEOLOG

12/03/2018, 5:00 PM
No, that's not what i need
d

diesieben07

12/03/2018, 5:00 PM
Then I don't see what you want... 😄
What exactly does the boolean flag not solve?
a

APXEOLOG

12/03/2018, 5:04 PM
I does not solve the situation when i need 5 separate blocks to run once as i don't want to add 5 flags
d

diesieben07

12/03/2018, 5:05 PM
Lazy solves exactly this problem though...
a

APXEOLOG

12/03/2018, 5:08 PM
Ok here is the case: I have a code that runs every few ms repeatedly, i need to print some output when the specific not-rare case inside of this code is happened but i need only to print it once, since i don't want to flood log with text