// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

var List = require("bs-platform/lib/js/list.js");
var Curry = require("bs-platform/lib/js/curry.js");
var Caml_obj = require("bs-platform/lib/js/caml_obj.js");
var Caml_option = require("bs-platform/lib/js/caml_option.js");
var Json_decode = require("@glennsl/bs-json/src/Json_decode.bs.js");

function zipBy(showKey, merge, getKeyFromOptional, getKeyFromRequired, optionals, requireds) {
  if (!requireds) {
    return /* [] */0;
  }
  var r = requireds.hd;
  var o = List.find_opt((function (o) {
          var k = Curry._1(getKeyFromOptional, o);
          return Caml_obj.caml_equal(k, Curry._1(getKeyFromRequired, r));
        }), optionals);
  if (o !== undefined) {
    return {
            hd: Curry._2(merge, Caml_option.valFromOption(o), r),
            tl: zipBy(showKey, merge, getKeyFromOptional, getKeyFromRequired, optionals, requireds.tl)
          };
  }
  throw {
        RE_EXN_ID: Json_decode.DecodeError,
        _1: "zipBy: No matching entry found at key " + Curry._1(showKey, Curry._1(getKeyFromRequired, r)),
        Error: new Error()
      };
}

function zipByPartition(showKey, mapBoth, mapSingle, getKeyFromOptional, getKeyFromRequired, optionals, requireds) {
  if (!requireds) {
    return [
            /* [] */0,
            /* [] */0
          ];
  }
  var rs = requireds.tl;
  var r = requireds.hd;
  var o = List.find_opt((function (o) {
          var k = Curry._1(getKeyFromOptional, o);
          return Caml_obj.caml_equal(k, Curry._1(getKeyFromRequired, r));
        }), optionals);
  if (o !== undefined) {
    var param = zipByPartition(showKey, mapBoth, mapSingle, getKeyFromOptional, getKeyFromRequired, optionals, rs);
    return [
            {
              hd: Curry._2(mapBoth, Caml_option.valFromOption(o), r),
              tl: param[0]
            },
            param[1]
          ];
  }
  var param$1 = zipByPartition(showKey, mapBoth, mapSingle, getKeyFromOptional, getKeyFromRequired, optionals, rs);
  return [
          param$1[0],
          {
            hd: Curry._1(mapSingle, r),
            tl: param$1[1]
          }
        ];
}

exports.zipBy = zipBy;
exports.zipByPartition = zipByPartition;
/* No side effect */
