Scala Option higher order functions instead of pattern matching

161 views Asked by At

What is the higher order function equivalent expression to the following?

def isRepeated:Boolean = {
  prev match {
    case Some(a) => a.prev match {
      case Some(b) => b.equals(this)
      case None => false
    }
    case None => false
  }
}
1

There are 1 answers

1
Tzach Zohar On BEST ANSWER

I believe this is equivalent:

def isRepeated:Boolean = prev.exists(_.prev.exists(_.equals(this)))