Skip to content

Instantly share code, notes, and snippets.

@tkellogg
Created March 30, 2016 07:06
Show Gist options
  • Save tkellogg/db7c03e5cff064d2b0f8ff415caefbfe to your computer and use it in GitHub Desktop.
Save tkellogg/db7c03e5cff064d2b0f8ff415caefbfe to your computer and use it in GitHub Desktop.
def mergeFields(vs1: List[JField], vs2: List[JField]): List[JField] = {
def mergeRec(xleft: List[JField], yleft: List[JField]): List[JField] = xleft match {
case Nil => yleft
case (xn, xv) :: xs => yleft find (_._1 == xn) match {
case Some(y @ (yn, yv)) =>
JField(xn, merge(xv, yv)) :: mergeRec(xs, yleft filterNot (_ == y))
case None => JField(xn, xv) :: mergeRec(xs, yleft)
}
}
mergeRec(vs1, vs2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment