Question | Click to View Answer |
What does the following code print? def myDivider(x: Int, y: Int): Either[String, Int] = {
if (y == 0) Left("You can't divide by zero")
else Right(x / y)
}
println(myDivider(5, 0))
|
The If If
|
What does the following code print? def myDivider(x: Int, y: Int): Either[String, Int] = {
if (y == 0) Left("You can't divide by zero")
else Right(x / y)
}
println(myDivider(10, 2))
|
Ten divided by two returns an integer, so a method with the |
What does the following code print? import scala.io.Source
def getProtocol(url: java.net.URL): Either[String, Source] =
if (url.getProtocol == "http")
Left("Please use https")
else
Right(Source.fromURL(url))
val url = new java.net.URL("http://www.codequizzes.com")
println(getProtocol(url))
|
The |
What does the following code print? import scala.io.Source
def getProtocol(url: java.net.URL): Either[String, Source] =
if (url.getProtocol == "http")
Left("Please use https")
else
Right(Source.fromURL(url))
val url = new java.net.URL("https://www.mungingdata.com")
println(getProtocol(url))
|
|
what does the following code print? Left("hi").getOrElse("whatever")
|
|
what does the following code print? Right("hi").getOrElse("whatever")
|
|