假设我有这样的函数:
def foo(x: Int): Int = ??? def bar(xs: List[Int]): List[Int] = xs map { case x if (x > 0) => x case x if (foo(x) > 0) => foo(x) + 1 case _ => 0 }
问题是foo被叫两次.你怎么写只打一次bar电话foo?
foo
bar
scala pattern-matching
pattern-matching ×1
scala ×1