Using zipWithIndex or zip to Create Loop Counters in Scala.
Briefly

days.zipWithIndex.foreach { case(day, count) => println(s"$count is $day")}
This approach simplifies the process of iterating over collections with an automatically generated counter, enhancing code readability and efficiency.
Read at Medium
[
|
]