groupBy 方法(或屬性)屬於 scala.collection.IterableOps 特性(trait),其相關用法說明如下。
用法:
def groupBy[K](f: A => K): Map[K, C]根據某些鑒別器函數將此可迭代集合劃分為可迭代集合的映射。
注意:即使應用於視圖或惰性集合,它也會始終強製元素。
- 類型參數:
- K
- 鑒別器函數返回的鍵的類型。 
 
- 值參數:
- f
- 判別器函數。 
 
- 返回:
- 從鍵到可迭代集合的映射,使得以下不變量成立: - (xs groupBy f)(k) = xs filter (x => f(x) == k)- 也就是說,每個鍵 - k都綁定到這些元素的可迭代集合- x其中- f(x)等於- k。
- 源碼:
- Iterable.scala
相關用法
- Scala IterableOps.groupMap用法及代碼示例
- Scala IterableOps.groupMapReduce用法及代碼示例
- Scala IterableOps.sizeIs用法及代碼示例
- Scala IterableOps.tails用法及代碼示例
- Scala IterableOps.mkString用法及代碼示例
- Scala IterableOps.unzip3用法及代碼示例
- Scala IterableOps.scanRight用法及代碼示例
- Scala IterableOps.addString用法及代碼示例
- Scala IterableOps.partitionMap用法及代碼示例
- Scala IterableOps.inits用法及代碼示例
- Scala IterableOps.unzip用法及代碼示例
- Scala IterableOps.sizeCompare用法及代碼示例
- Scala IterableOps.sliding用法及代碼示例
- Scala IterableOps.collectFirst用法及代碼示例
- Scala IterableOps.transpose用法及代碼示例
- Scala IterableOnceOps.flatMap用法及代碼示例
- Scala IterableOnceOps.mkString用法及代碼示例
- Scala IterableOnceOps.addString用法及代碼示例
- Scala IterableOnceOps.collectFirst用法及代碼示例
- Scala IterableOnceOps.slice用法及代碼示例
- Scala IterableOnceOps.flatten用法及代碼示例
- Scala IterableOnceOps.zipWithIndex用法及代碼示例
- Scala Iterable.sizeCompare用法及代碼示例
- Scala IterableFactoryDefaults.groupMap用法及代碼示例
- Scala Iterable.transpose用法及代碼示例
注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 IterableOps.groupBy。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
