Last active
April 28, 2016 12:23
-
-
Save joakim-ribier/06cb1896039c6a842602 to your computer and use it in GitHub Desktop.
@scala.annotation.tailrec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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