I am designing a program. I am new to Scala but it seems optional arguments are handled using the following:
def f1(my_string: Option[String] = None) = {
// Maybe do some pattern matching here to extract the value
}
However, for an end user this is pretty ugly as they will need to call this function like:
f1(Some("foo")
Is there a technique or pattern to turn this into:
f1("foo"))
and still work with an optional argument?i.e f1() also works?
The reason I ask is I have obviously used Scala libraries where adding an explicit Some(..) has not been necessary, but in their source code they have defined functions as above. I would personally use a default argument but wandering why this is a design pattern.