I have a DateTime and TimeSpan class in Scala (assume that the < and + operators work as they should). I'm trying to define a 'range' function that takes a start/stop time and a timespan for stepping. In C# I would do this with a yield, and I think I should be able to do the same in Scala... except I'm getting a strange error.
'Verim t' çizgisinde, "Yasadışı ifadenin başlangıcı" alırım.
def dateRange(from : DateTime, to : DateTime, step : TimeSpan) =
{
//not sure what the list'y way of doing this is
var t = from
while(t < to)
{
yield t;//error: illegal start of statement
t = t + step
}
}
Bu koda baktığımda, 2 şey hakkında merak ediyorum:
1) neyi yanlış yaptım?
2) Yazılan kod çok zorlayıcıdır (var t, vb. Kullanır). Scala'da bunu oldukça hızlı yapan daha işlevsel yol nedir?
Teşekkürler!