Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use a closure to track whether the function has been called via a boolean flag. On the first call, execute the function, store the result, and set the flag. On subsequent calls, return the cached result without re-executing.
The closure captures a mutable boolean and result variable that persist across calls, ensuring the wrapped function body runs exactly once regardless of how many times the wrapper is invoked.
Updated Feb 2026