Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
So I have a list of tuples that looks like (a, (b, x)). I want as a result a map of a to (b, x) where x is the greatest x for that given a and b combo. Basically, if the x I'm examining is greater than the greatest x so far for that a as well as that b, update the result map with the a, (b, x) combo. I have legitimately no idea how to approach this. It seems like I should be able to do this with foldLeft, am I crazy?

Adbot
ADBOT LOVES YOU

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Thanks for this. Basically, my input is something like [ (A, (B, X)), (A, (C, X)), (A, (D, X), (A, (C, Y)), (A, (C, Z)))] and so on. It's a mapping of an Id, to tuples containing a value and a timestamp for that value. I have no choice as to how that's represented, but I do have some leeway over how I process it and reach my desire result of Map[A, (C, (maximum of X, Y, Z)].

This is one of the harder things I've done in Scala so far (I'm using Spark) but it's really neat and I'm enjoying it so far.

  • Locked thread