def groupBy[K, CC[_, _]](mapFactory: MapFactory[CC])(f: A => K): CC[K, C]
def groupBy[K, CC[_, _]](mapFactory: MapFactory[CC])(f: A => K): CC[K, Array[A]]
def groupBy[K, CC[_, _]](mapFactory: MapFactory[CC])(f: A => K): CC[K, IArray[A]]
And then ,the usage can be
1 import scala.collection.immutable.{ListMap, VectorMap}
2
3 val xs = List(3, 1, 4, 1, 5, 9, 2, 6)
4 val grouped: ListMap[Int, List[Int]] = xs.groupBy(ListMap)(_ % 3)
5 // ListMap(0 -> List(3, 9, 6), 1 -> List(1, 1, 4), 2 -> List(5, 2))
6 // keys appear in first-seen order: 3 (key 0), 1 (key 1), 5 (key 2)