1

Here is my implementation of a simple aggregation.

  val mapping = Map("AA" -> "A", "AB" -> "A", "B" -> "B")
  val input = Map("AA" -> 1, "AB" -> 1, "B" -> 1)

  val output = input.groupBy { case (k, _) => mapping(k) }
               .mapValues(_.values.sum)

Is there a smarter implementation using scalaz ?

Yann Moisan
  • 8,161
  • 8
  • 47
  • 91

1 Answers1

0

Finally got this one, leverging a bit some monoids

val output = input.toList.map { case (k, v) => Map((mapping(k), v)) }.reduce( _ |+| _)

Not sure if it's better in term of memory and/or CPU.

Yann Moisan
  • 8,161
  • 8
  • 47
  • 91