I’ve been programming for a little while with Core_kernel and I’m trying to figure out a good way to merge two Maps together. I’m confused about why this doesn’t work:
let map_merge map1 map2 = Map.Poly.fold map1 ~init:map2 ~f:Map.Poly.add_exn
It looks like
add_exn expects the map argument first, but
fold will only work with something that takes it last? What’s going on here? Is there some recommended pattern?
PS Here is my current level-best:
let merge_maps maps = List.map ~f:Map.Poly.to_alist maps |> List.concat |> Map.Poly.of_alist_exn