I’m a newbie to scala, I’m just writing a simple function to reverse a given string:
def reverse(s: String) : String
for(i <- s.length - 1 to 0) yield s(i)
the yield gives back a scala.collection.immutable.IndexedSeq[Char], and can not convert it to a String. (or is it something else?)
how do i write this function ?
Note that there is already defined function:
But if you want to do that by yourself:
or (sometimes it is better to use
until, but probably not in that case)Also, note that if you use reversed counting (from bigger one to less one value) you should specify negative step or you will get an empty set: