How to make this code more functional, where a value from the current iteration is preserved into the next (variable last),
def f(i: Int): Int = ???
var last = -1
for (v <- xs) yield {
val start = f(v)
val end = f(start)
val res = if (last == start - 2) "abc" else "xyz"
last = end
res
}