I am trying to port python code (spark sql distance to nearest holiday)
last_holiday = index.value[0]
for next_holiday in index.value:
if next_holiday >= date:
break
last_holiday = next_holiday
if last_holiday > date:
last_holiday = None
if next_holiday < date:
next_holiday = None
to scala. I do not (yet) have so much scala experience, but break
does not seem clean / the scala way to do it. Please, can you show me how to "cleanly" port this to scala.
breakable {
for (next_holiday <- indexAT.value) {
val next = next_holiday.toLocalDate
println("next ", next)
println("last ", last_holiday)
if (next.isAfter(current) || next.equals(current)) break
// check do I actually get here?
last_holiday = Option(next)
} // TODO this is so not scala and ugly ...
if (last_holiday.isDefined) {
if (last_holiday.get.isAfter(current)) {
last_holiday = None
}
}
if (last_holiday.isDefined) {
if (last_holiday.get.isBefore(current)) {
// TODO use one more var because out of scope
next = None
}
}
}
Here the same code in a bit more context https://gist.github.com/geoHeil/ff513b97a2b3e16241fdd9c8b0f3bdfb Also, I am not sure how "big" I should put the break - but I hope to get rid of it in a scala native port of the code.