Pattern matching is more idiomatic in Scala and more easily protects you from boundary conditions.
In code
private def next() { val item = agenda.head agenda = agenda.tail curtime = item.time item.action() }
Both agenda.head
and agenda.tail
will throw a NoSuchElementException
if agenda
is an empty list, so for it to actually work you need to add a check for this.
The corresponding version of the template actually has a similar problem (as indicated in the comments), but I will find a fix because all you have to do is add another template:
private def next() { (agenda: @unchecked) match { case item :: rest => agenda = rest curtime = item.time item.action() case _ => {} } }
Don roby
source share