从Scala 中的函数式编程,我正在尝试实现Either.map
.
trait Either[+E, +A] {
def map[B](f: A => B): Either[E, B] = this match {
case Either(x: E, y: A) => Right(f(y))
case _ => Left()
}
}
除其他外,编译时出现一个错误。我没有展示它们,因为我似乎缺少实施的概念Either.
Either.scala:3: error: value Either is not a case class constructor,
nor does it have an unapply/unapplySeq method
case Either(x: E, y: A) => Right(f(y))
请告诉我实施它。