Construct date sequence in Scala I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...]

Then I define a stream to do that.

def daySeq(start: Date): Stream[Date] = Stream.cons(start,  daySeq(plusDays(start, 1)))


I get the sequence within range [start, end) by calling 

daySeq(from).takeWhile(_.getTime &lt; to.getTime)


Any better/simple solution to do this ?
I suggest using Joda-Time's LocalDate instead of Java's Date to represent dates without a time zone.

Assuming you only need to traverse the days once, use an Iterator instead of a Stream.

def dayIterator(start: LocalDate, end: LocalDate) = Iterator.iterate(start)(_ plusDays 1) takeWhile (_ isBefore end)


Example usage: 

dayIterator(new LocalDate("2013-10-01"), new LocalDate("2014-01-30")).foreach(println)


If you do need a lazily-evaluated list, then Stream is appropriate. I suggest using iterate instead of cons in that case.

def dayStream(start: LocalDate, end: LocalDate) = Stream.iterate(start)(_ plusDays 1) takeWhile (_ isBefore end)