Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
object TailRecursiveCounter {
var count = 0
var isDark = false
def updateUI(): Unit = println(s"Counter: $count, Theme: ${if(isDark) "Dark" else "Light"}")
@annotation.tailrec
def simulate(steps: List[String]): Unit = steps match {
case Nil => updateUI()
case head :: tail => head match {
case "inc" => count += 1
case "dec" => count -= 1
case "toggle" => isDark = !isDark
}; updateUI(); simulate(tail)
}
def main(args: Array[String]): Unit = simulate(List("inc","inc","toggle","dec","reset"))
}
TailRecursiveCounter.main(Array())Coding works best on desktop or with an external keyboard.