In this code I want to increment index to put it to each yielding result.
index
yield
var index=0 for(str <- splitToStrings(text) ) yield
The zipWithIndex method on most sequence-like collections will give you a zero-based index, incrementing with each element:
zipWithIndex
for ((str, index) <- splitToStrings(text).zipWithIndex) yield new Word(str, UNKNOWN_FORM, index)