Scala implementation