1

I have the follow function in Scala:

def boolOrNone(n: NodeSeq): Option[Boolean] = {
    Some(Try((n.text.toBoolean)).getOrElse(None)) 
}

The problem is that it won't compile because it returns type Option[Any] which makes sense but I need this method to return Option[Boolean] What is the best way to return a none type if the n.text.toBoolean fails?

1 Answer 1

6

I believe you just want Try(n.text.toBoolean).toOption

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.