There are multiple ways to do that. You can of course extends Function1[Input, Output] (let's focus only on unary functions). Actually, there is also another, more idiomatic manner to write a function in Scala. Instead of extending a class, you can extend the function's signature like extends (Input => Output):
object StringToIntegerMapper extends (String => Integer) { override def apply(text: String): Integer = text.toInt } object StringToIntegerMapperFunction1 extends Function1[String, Integer] { override def apply(text: String): Integer = text.toInt }
Of course, if you run a simple assertions, you will get the same result:
assert(StringToIntegerMapper("1") == 1 && StringToIntegerMapperFunction1("1") == 1)