I'm confused with Scala's syntax again. I expected this to work just fine:
// VERSION 1
def isInteractionKnown(service: Service, serviceId: String) = service match {
case TwitterService =>
twitterInteractions.findUuidByTweetId(serviceId.toLong)
case FacebookService =>
facebookInteractions.findUuidByServiceId(serviceId)
}.isDefined
NOTE: Both findUuidByTweetId
and findUuidByServiceId
return an Option[UUID]
scalac
tells me:
error: ';' expected but '.' found.
}.isDefined
When I let my IDE (IDEA) reformat the code, .isDefined
part ends up on a line of it's own. It's as if match
isn't an expression. But in my mind, what I did was functionally equivalent to:
// VERSION 2
def isInteractionKnown(service: Service, serviceId: String) = {
val a = service match {
case TwitterService =>
twitterInteractions.findUuidByTweetId(serviceId.toLong)
case FacebookService =>
facebookInteractions.findUuidByServiceId(serviceId)
}
a.isDefined
}
which parses and does exactly what I want. Why is the first syntax not accepted?