Rewriting to Scala