-
-
Save xydinesh/8290519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groupBy('source) { | |
_.sortBy('links) | |
.reverse | |
.mapStream[(String,Int), (String, Int, Int, Int)] | |
(('destination, 'links) -> ('destination, 'links, 'rank, 'gap)) { destLinks => | |
destLinks.scanLeft(None: Option[(String, Int, Int, Int)]) { | |
(prevRowOut: Option[(String,Int,Int,Int)], thisRow: (String, Int)) => | |
val (dest, links) = thisRow | |
prevRowOut match { | |
case None => Some((dest, links, 1, 0)) // rank 1, gap 0 -- not exactly what you wanted... | |
case Some((prevDest, prevLinks, prevRank, prevGap)) => | |
Some(dest, links, prevRank + 1, prevLinks - links) | |
} | |
} | |
.collect { case Some(x) => x } // drop the initial None, and unwrap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment