I am trying to figure out how to use a function as a member of a class, but can not figure out the correct syntax. I get an compilation error:
test.scala:11: error: missing arguments for method extra in class RichString;
follow this method with `_' if you want to treat it as a partially applied function
println("This is".extra);
How would I keep extra as a function defined outside of the class RichString and use it to extend the String class?
Thanks.
test.scala:
class RichString(a: String) {
def extra(a: String):String
}
def extra(a: String): String = {
return a+" Extra!";
}
implicit def string2Rich(s: String) = new RichString(s);
println("This is".extra);
Is this what you want?