Join 2 maps in scala, similar to left outer join

2,231 views
Skip to first unread message

Jun Yamog

unread,
Jun 4, 2012, 4:55:59 PM6/4/12
to scala-user
Would like to ask help and get some suggestions. I am doing something
similar to a left outer join in sql but done in scala. We needed some
to join 2 sets of data coming from 2 different data sources. Here is
the code below:

https://gist.github.com/2870693

It seems to work, however is there something in the collection API
that would do something similar? If not is this a good way to do it?

Thanks very much.

Rex Kerr

unread,
Jun 4, 2012, 5:36:07 PM6/4/12
to Jun Yamog, scala-user
Your code is not a very direct path to the goal.  You only need

  map1.map{ case(k,v) => k -> (Some(v), map2.get(k)) }

since there's no point taking apart the option from a map.get only to put it back together again.

  --Rex

Jun Yamog

unread,
Jun 4, 2012, 8:48:43 PM6/4/12
to scala-user
Thanks Rex, makes better sense. I have much to learn on Scala AND to
unlearn on Java

Jun
Reply all
Reply to author
Forward
0 new messages