Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created August 29, 2013 15:38
Show Gist options
  • Save andypetrella/6379713 to your computer and use it in GitHub Desktop.
Save andypetrella/6379713 to your computer and use it in GitHub Desktop.
MR scala
//def
val l:List[A]
val m[K,V]:A=>List[(K, V)]
val r[V]:List[V]=>V
val s[K]:K=>K
//mr
l.flatMap(m)
.groupBy(_._1)
.mapValues(_.map(_._2))
.groupBy{case (x, xs) => s(x) }
.mapValues(map => map.map{ case (x, xs) => (x, r(xs))})
.values
.flatten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment