Given a range, getting all dates within that range in Scala

前端 未结 6 1854
礼貌的吻别
礼貌的吻别 2021-02-04 03:29

I need to make a function in scala that, given a range of dates, gives me a list of the range. I am relatively new in Scala and I am not able to figure out how to write the righ

6条回答
  •  梦谈多话
    2021-02-04 04:13

    Since Scala is a functional, go with a recursion:

    def calculateDates(from: LocalDate, until: LocalDate): Seq[LocalDate] = {
        if from.compareTo(until) > 1
            return[]
        else
            return from :: calculateDates(from.plusDays(1), until)
    } 
    

提交回复
热议问题