I have a DateTime and TimeSpan class in Scala (suppose the <and + operators work as they should). I am trying to define a range function that takes a start / stop time and a period of time for a step. In C #, I would do it with profitability, and I think I would have to do the same in Scala ... except that I get a strange error.
In the line "yield t" I get "Illegal start of the statement".
def dateRange(from : DateTime, to : DateTime, step : TimeSpan) =
{
var t = from
while(t < to)
{
yield t;
t = t + step
}
}
Looking at this code, I am interested in 2 things: 1) what did I do wrong? 2) code written very strongly (uses var t, etc.). What is a more functional way to do this in Scala, which is fast enough?
Thank!