It eventually calls my css function passing some varargs. Let’s assume I want any title to be large. I could do something like larger + ";" + css(styles:_*) but this requires me to rewrite the “logic” on how strings get joined. Is there any way I could merge append larger to my varargs before passing them? And is there any way to restrict the parameters passed to title to those defined in Styles excluding larger (as it is supposed to be set by default).
One option for more type safety would be wrapping your Strings in some wrapper class. This class could have some combine method, and you could also define an implicit conversion to a plain String to be able to use String’s methods. Something along the lines of:
case class Style (style:String) { def combine(s: Style) : Style = ??? }
object larger extends Style(“font-size : 12pt”)
object important …
…
with an implicit conversion in scope ( something like implicit def styleToString(s: Style): String= s.style )
you could use all String utility methods on your Styles, ie. you could do like larger.toUpperCase, without having to manually unwrap the String all the time.