Add convenient alternate for Map.merge?

Maybe there should be an additional function:

let mergeSimple: (
  t<'k, 'v, 'id>,
  t<'k, 'v, 'id>,
  ('k, 'v, 'v2) => option<'v3>,
  ('k, 'v) => option<'v3>,
) => t<'k, 'v3, 'id>


Would you implement it like this?

let mergeSimple = (a, b, f, g) =>
  Belt.Map.merge(a, b, (k, a, b) =>
    switch (a, b) {
    | (None, None) => None
    | (Some(a), Some(b)) => f(k, a, b)
    | (Some(x), None) | (None, Some(x)) => g(k, x)

Convenience is subjective, since I think the current merge implementation is pretty simple already (except for the unused (None, None) case). Arguably, it’s simpler to write only one callback function instead of two. Whichever version you use, you’ll probably end up writing about the same number of lines of code.

But that’s all just my opinion. :slightly_smiling_face: If you find this function to be more convenient, then feel free to use it!

Would you implement it like this?


(except for the unused (None, None) case)

It just seems strange to have to keep matching on (None, None) because of an internal detail of the implementation.