runWith
方法(或屬性)屬於 scala.collection.mutable.AbstractBuffer
類(class),其相關用法說明如下。
用法:
def runWith[U](action: A => U): Int => Boolean
將此部分函數與一個作用函數組合在一起,該作用函數應用於此部分函數的結果。調用動作函數隻是為了它的副作用;它的結果被忽略。
請注意,表達式pf.runWith(action)(x)
等價於
if(pf isDefinedAt x) { action(pf(x)); true } else false
除了 runWith
是通過 applyOrElse
實現的,因此可能更有效。使用 runWith
可以避免對模式匹配器和部分函數文字的保護進行雙重評估。
值參數:
- action
動作函數
返回:
將參數
x
映射到isDefinedAt(x)
的函數.結果函數運行action(this(x))
,其中定義了this
。也可以看看:
applyOrElse
.繼承自:
- PartialFunction.runWith
源碼:
- PartialFunction.scala
相關用法
- Scala AbstractBuffer.unzip用法及代碼示例
- Scala AbstractBuffer.elementWise用法及代碼示例
- Scala AbstractBuffer.prepended用法及代碼示例
- Scala AbstractBuffer.appended用法及代碼示例
- Scala AbstractBuffer.addString用法及代碼示例
- Scala AbstractBuffer.sizeIs用法及代碼示例
- Scala AbstractBuffer.lengthCompare用法及代碼示例
- Scala AbstractBuffer.collectFirst用法及代碼示例
- Scala AbstractBuffer.groupMapReduce用法及代碼示例
- Scala AbstractBuffer.tails用法及代碼示例
- Scala AbstractBuffer.applyOrElse用法及代碼示例
- Scala AbstractBuffer.sortWith用法及代碼示例
- Scala AbstractBuffer.partitionMap用法及代碼示例
- Scala AbstractBuffer.transpose用法及代碼示例
- Scala AbstractBuffer.combinations用法及代碼示例
- Scala AbstractBuffer.groupBy用法及代碼示例
- Scala AbstractBuffer.mkString用法及代碼示例
- Scala AbstractBuffer.unzip3用法及代碼示例
- Scala AbstractBuffer.lengthIs用法及代碼示例
- Scala AbstractBuffer.scanRight用法及代碼示例
- Scala AbstractBuffer.sliding用法及代碼示例
- Scala AbstractBuffer.permutations用法及代碼示例
- Scala AbstractBuffer.groupMap用法及代碼示例
- Scala AbstractBuffer.inits用法及代碼示例
- Scala AbstractBuffer.sortBy用法及代碼示例
注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 AbstractBuffer.runWith。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。