I'm trying to design a DSL in Scala. For that, I'd like to create an implicit function on precise strings. I know that to create an implicit function for any String, I could write:
class StringPlus(str: String) {
def some_function(): Unit = do_something
}
implicit def string2StringPlus(str: String) = new StringPlus(str)
But I do not know how to modify this to create this implicit function only for certain strings. Could it be possible to give a boolean condition to the implicit function so that the implicit function is created only when the boolean condition is true (for instance, if the string has a length of 5 or more, if the first letter of the string is the letter "a", etc.) and not for all the strings ?
magicMethod "this-is-always-foo"
) or are they run-time dependent (e. g.magicMethod readFromStdIO
)? – Dicarlo