All Downloads are FREE. Search and download functionalities are using the official Maven repository.

axle.MapReduce.scala Maven / Gradle / Ivy

The newest version!
package axle

trait MapReduce {

  def apply[D, K, V](data: Iterable[D], mapper: D => Seq[(K, V)], reducer: (V, V) => V): Map[K, V]

}

object ScalaMapReduce extends MapReduce {

  def apply[D, K, V](data: Iterable[D], mapper: D => Seq[(K, V)], reducer: (V, V) => V): Map[K, V] =
    data
      .flatMap(mapper)
      .groupBy(_._1)
      .map({ case (k, v) => (k, v.map(_._2).reduce(reducer)) })

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy