Scala solution without implicits