playframework - Iterate over scala list -
i have list of strings in scala template of play framework.
want iterate on half of list @ 1 time , other half of list on second time.
not sure how write efficient iterator this.
i have tried
@for(i <- 0 until list.length/2 ) {list(i) }
, second loop
@for(i <- list.length/2+1 until list.length ) { list(i) }
works complexity becomes high.
then later did
@defining(list.size) { size => @for(i <- 0 until size/2) {list(i) } }
seems work fine.
here's 1 way.
scala> list("a","b","c","d","e") res0: list[string] = list(a, b, c, d, e) scala> res0.splitat(res0.size/2) res1: (list[string], list[string]) = (list(a, b),list(c, d, e)) scala> res1._1.foreach(println(_)) b scala> res1._2.foreach(println(_)) c d e