After fixing the code, deleting def {, it compiled just fine:
scala> object Test {
| implicit def intToMyRichInt(count: Int) = {
| new {
| def times(f: => Unit) =
| 1 to count foreach { _ => f }
| }
| }
| }
defined module Test
It is also recommended that you remove {} after the implicit def:
object Test {
implicit def intToMyRichInt(count: Int) =
new {
def times(f: => Unit) =
1 to count foreach { _ => f }
}
}
, , {... class content...} , . :
object Test {
class MyRichInt(x:Int) {
def times(f: => Unit) = 1 to x foreach { _ => f }
}
implicit def intToMyRichInt(count: Int) = new MyRichInt(count)
}
.