I try to build a simple implicit class on Int
to add a function for Ints:
object Helper {
implicit class IntHelper(i: Int) {
def add(str: String): Int = i + str.toInt
}
}
To be more natural to write, I would like the DSL to allow this (with import Helper._
):
2 add "3" and add "4"
but I cannot figure out how to do the and
function. I thought this one would work:
object Helper {
implicit class IntHelper(i: Int) {
def add(str: String): Int = i + str.toInt
def and: Int = i
}
}
but it does not work without the parentheses (indeed, "2.add("3").and.add("4")
works but imo there are too many full-stops and parentheses for a DSL).
Thanks