0
我有以下的集合:斯卡拉ifNotPresent简洁的形式
private val commandChain: mutable.Buffer[mutable.Buffer[Long]] = ArrayBuffer()
我需要做到以下几点:
def :->(command: Long) = {
commandChain.headOption match {
case Some(node) => node += command
case None => commandChain += ArrayBuffer(command)
}
}
是否有这种更简洁的形式比模式匹配?
您的意思是这个速度更快? –
也许,但我认为你会很难找到可衡量的性能差异。这只是稍微简洁一些,并提供更多的可读性和清晰度的目的,恕我直言。 – jwvh