group by key in haskell
Haskell
Scala
Programming
什麼是 Group By Key
Group By Key 就是把 Element 計算一個 key,相同 key 的 element 就放左一組內 例如 group by key by the reminder equal to 3 in Scala
val arr = Array(2, 4, 5, 6, 9, 23, 24, 25, 31, 37)
scala> val ans = arr.groupBy { n => n % 3 }
ans: scala.collection.immutable.Map[Int,Array[Int]] = Map(2 -> Array(2, 5, 23), 1 -> Array(4, 25, 31, 37), 0 -> Array(6, 9, 24))
問題
Haskell 中把 List 中的 element Group By Key 是麻煩的一件事
因為 Data.List.groupBy
…