groupMapReduce 方法(或属性)属于 scala.collection.AbstractIndexedSeqView 类(class),其相关用法说明如下。
用法:
def groupMapReduce[K, B](key: A => K)(f: A => 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 AbstractIndexedSeqView.groupMap用法及代码示例
 - Scala AbstractIndexedSeqView.groupBy用法及代码示例
 - Scala AbstractIndexedSeqView.collectFirst用法及代码示例
 - Scala AbstractIndexedSeqView.partitionMap用法及代码示例
 - Scala AbstractIndexedSeqView.sliding用法及代码示例
 - Scala AbstractIndexedSeqView.addString用法及代码示例
 - Scala AbstractIndexedSeqView.unzip用法及代码示例
 - Scala AbstractIndexedSeqView.tails用法及代码示例
 - Scala AbstractIndexedSeqView.transpose用法及代码示例
 - Scala AbstractIndexedSeqView.mkString用法及代码示例
 - Scala AbstractIndexedSeqView.sortBy用法及代码示例
 - Scala AbstractIndexedSeqView.sizeIs用法及代码示例
 - Scala AbstractIndexedSeqView.lengthIs用法及代码示例
 - Scala AbstractIndexedSeqView.combinations用法及代码示例
 - Scala AbstractIndexedSeqView.inits用法及代码示例
 - Scala AbstractIndexedSeqView.lazyZip用法及代码示例
 - Scala AbstractIndexedSeqView.unzip3用法及代码示例
 - Scala AbstractIndexedSeqView.sortWith用法及代码示例
 - Scala AbstractIndexedSeqView.permutations用法及代码示例
 - Scala AbstractIndexedSeqView.scanRight用法及代码示例
 - Scala AbstractIterator.sliding用法及代码示例
 - Scala AbstractIterable.partitionMap用法及代码示例
 - Scala AbstractIterable.inits用法及代码示例
 - Scala AbstractIterable.groupMap用法及代码示例
 - Scala AbstractIterable.sizeIs用法及代码示例
 
注:本文由纯净天空筛选整理自scala-lang.org大神的英文原创作品 AbstractIndexedSeqView.groupMapReduce。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
