Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created October 16, 2012 10:11
Show Gist options
  • Save arturaz/3898478 to your computer and use it in GitHub Desktop.
Save arturaz/3898478 to your computer and use it in GitHub Desktop.
intermediateLocations match {
case Nil =>
f(oDeparture, tArrival)
case intermediate :: Nil =>
f(oDeparture, iArrival(intermediate))
f(iDeparture(intermediate), tArrival)
case _ =>
f(oDeparture, iArrival(intermediateLocations.head))
val last = intermediateLocations.sliding(2).
foldLeft(intermediateLocations.head) {
case (last, i1 :: i2 :: Nil) =>
f(iDeparture(i1), iArrival(i2))
i2
case _ => sys.error("Non-exhaustive match here")
}
f(iDeparture(last), tArrival)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment