Skip to content

Instantly share code, notes, and snippets.

@darkjh
Last active August 29, 2015 14:00
Show Gist options
  • Save darkjh/11378559 to your computer and use it in GitHub Desktop.
Save darkjh/11378559 to your computer and use it in GitHub Desktop.
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