groupMapReduce
方法(或屬性)屬於 scala.collection.immutable.TreeSeqMap
類(class),其相關用法說明如下。
用法:
def groupMapReduce[K, B](key: ((K, V)) => K)(f: ((K, V)) => B)(reduce: (B, B) => B): Map[K, B]
根據鑒別函數key
將此可迭代集合劃分為映射.然後,所有具有相同鑒別器的值由f
函數轉換,然後使用reduce
函數簡化為單個值。
它等效於 groupBy(key).mapValues(_.map(f).reduce(reduce))
,但效率更高。
def occurrences[A](as: Seq[A]): Map[A, Int] =
as.groupMapReduce(identity)(_ => 1)(_ + _)
注意:即使應用於視圖或惰性集合,它也會始終強製元素。
相關用法
- Scala TreeSeqMap.groupMap用法及代碼示例
- Scala TreeSeqMap.groupBy用法及代碼示例
- Scala TreeSeqMap.sizeIs用法及代碼示例
- Scala TreeSeqMap.transpose用法及代碼示例
- Scala TreeSeqMap.mkString用法及代碼示例
- Scala TreeSeqMap.elementWise用法及代碼示例
- Scala TreeSeqMap.equals用法及代碼示例
- Scala TreeSeqMap.runWith用法及代碼示例
- Scala TreeSeqMap.sliding用法及代碼示例
- Scala TreeSeqMap.tails用法及代碼示例
- Scala TreeSeqMap.inits用法及代碼示例
- Scala TreeSeqMap.sizeCompare用法及代碼示例
- Scala TreeSeqMap.scanRight用法及代碼示例
- Scala TreeSeqMap.lazyZip用法及代碼示例
- Scala TreeSeqMap.addString用法及代碼示例
- Scala TreeSeqMap.collectFirst用法及代碼示例
- Scala TreeSet diff()用法及代碼示例
- Scala TreeSet contains()用法及代碼示例
- Scala TreeSet min()用法及代碼示例
- Scala TreeSet.groupMapReduce用法及代碼示例
- Scala TreeSet sum()用法及代碼示例
- Scala TreeSet find()用法及代碼示例
- Scala TreeSet.groupMap用法及代碼示例
- Scala TreeSet.sizeCompare用法及代碼示例
- Scala TreeSet dropRight()用法及代碼示例
注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 TreeSeqMap.groupMapReduce。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。