Skip to content

Instantly share code, notes, and snippets.

@joakim-ribier
Last active April 28, 2016 12:23
Show Gist options
  • Select an option

  • Save joakim-ribier/06cb1896039c6a842602 to your computer and use it in GitHub Desktop.

Select an option

Save joakim-ribier/06cb1896039c6a842602 to your computer and use it in GitHub Desktop.
@scala.annotation.tailrec
/**
* List days from interval {from - to}.
*
* @return a seq of LocalDate
*/
private def splitDayByDay(from: LocalDate, to: LocalDate): Seq[LocalDate] = {
@scala.annotation.tailrec
def splitDayByDayWithAccumulator(accumulator: Seq[LocalDate], from: LocalDate, to: LocalDate): Seq[LocalDate] = {
if (from.isEqual(to)) accumulator
else {
val fromPlusOneDay = from.plusDays(1)
splitDayByDayWithAccumulator(accumulator :+ fromPlusOneDay, fromPlusOneDay, to)
}
}
splitDayByDayWithAccumulator(Seq(from), from, to)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment