【发布时间】:2017-03-15 05:19:46
【问题描述】:
我正在编写一个返回 False 或值列表的递归函数。
def parse(chars: List[Char]): Either[List[Char], Boolean] = {
if (chars.length == 1)
chars
else {
val head = chars.head
val tail = parse(chars.tail)
tail match {
case Left(l) => {
if (are_equal(head, tail.head))
head :: tail
else if (are_cancelled(head, tail.head))
tail.tail
else
false
}
case Right(b) => false
}
}
}
我收到错误:value head is not a member of Either[List[Char],Boolean],但 head 方法只能在匹配列表后使用。
【问题讨论】:
标签: scala pattern-matching either