Suppose I have the following functions
def getHost():Option[String] = ... def getPort():Option[Int] = ...
Now I would like to use defaults if these functions return None.
def makeURL() = {
val host = getHost() getOrElse "localhost"
val port = getPort() getOrElse 8080
java.net.URL("http", host, port, "myPath")
}
Unfortunately this code does not look idiomatic in Scala. I would prefer makeURL to be more like a functions composition. How would you change makeURL?