i need some help with this code in scala, i want to implement foldL method but im getting this:
asd.scala:73: error: type mismatch;
found : Option[MyTree[A]] => B
required: B
def myFoldLeft[B](z: B)(op: (B, A) => B): B = (_:Option[MyTree[A]]) match {
^
one error found
I know thats a type missmatch but im newbie with scala and Oriented Object and i dont understand how to solve this situation.
class MyTree[A](val value: A, val left:Option[MyTree[A]],
val right:Option[MyTree[A]]) {
def myFoldLeft[B](z: B)(op: (B, A) => B): B = (_:Option[MyTree[A]]) match {
case Some(tree) => right.get.myFoldLeft (left.get.myFoldLeft (op(z, value)) (op)) (op)
case None => z
}
}
(_:Option[MyTree[A]]) ...
is a lambda.
You should match like
class MyTree[A](val value: A, val left:Option[MyTree[A]],
val right:Option[MyTree[A]]) {
def myFoldLeft[B](z: B)(op: (B, A) => B): B = (left, right) match {
case (Some(left), Some(right)) => ???
case (Some(left), None) => ???
case (None, Some(right)) => ???
case (None, None) => ???
}
}