What is the correct way to return None from a pattern match? Here is what I tried.
object Simulate {
def findFinal[Sigma,L,E](dfa:Dfa[L,E], delta:(Sigma,L)=>Boolean)(seq:Seq[Sigma]):Option[State[L,E]] = {
seq.foldLeft(Some(dfa.q0)) { (mq:Option[State[L,E]], s:Sigma) =>
mq match {
case None => None
case Some(q) =>
val maybeTransition = q.transitions.find { case Transition(_, l, _) => delta(s, l) }
maybeTransition match {
case Some(Transition(_, _, d: State[L, E])) => Some(d) // transition to state d
case None => None // found an input for which there is no valid transition from state q
}
}
}
}
But I get a compiler error.
Error:(29, 22) type mismatch;
found : None.type
required: Some[dfa.State[L,E]]
case None => None
The error is also displayed in IntelliJ