문제

I am using play2 framework, so when I retrieving parameters I always get Option. But I will only continue to process only if all the Options are matched (Not None).

I don't want to write nested match as that looks ugly.

if( isDefined("a") && isDefined("b"){
    //dosomething 
}
도움이 되었습니까?

해결책

You can match them as a tuple

(aOpt, bOpt) match {
  case (Some(aVal), Some(bVal)) => ...
  case _ => ...
}

You could use for-comprehension syntax

for {
  aVal <- aOpt
  bVal <- bOpt
} ...

There are also some monadic combinators ((aOpt |@| bOpt) {aVal + bVal}) in the Scalaz library if you want to go that road.

Here are a similar question + answers.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top