0

Is it possible to test to see how many times you've already looped over the map?

Something like the following:

@item.itemImgs.map { img =>
    @if(img._1) {
        <html stuff>
    }
}

The above is the Play Framework templating engine in a *.scala.html document.

bad at scala
  • 287
  • 1
  • 3
  • 11

1 Answers1

2

You can use zipWithIndex and get the element index, with that you know how many times you have mapped the collection, note that it's zero index based:

scala> List(1,2,3,4).zipWithIndex.map { case (e,i) => println(i + ": " + e ) }
0: 1
1: 2
2: 3
3: 4
om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Ende Neu
  • 15,581
  • 5
  • 57
  • 68