Last active
August 29, 2015 14:00
-
-
Save darkjh/11378559 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
type ParsedDoc = Map[String, Any] | |
type PartialDoc = (UID, ParsedDoc) | |
/** | |
* Recursively merge two parsed json documents | |
*/ | |
private def merge(map1 : ParsedDoc, map2 : ParsedDoc): ParsedDoc = { | |
def mergeValues(o1 : Option[Any], o2 : Option[Any]) = | |
(o1, o2) match { | |
case (Some(v1 : ParsedDoc), Some(v2 : ParsedDoc)) => merge(v1, v2) | |
case _ => (o1 orElse o2).get | |
} | |
(map1.keySet ++ map2.keySet) | |
.map(key => key -> mergeValues(map1.get(key), map2.get(key))) | |
.toMap | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment