merge = (xelements, yelements) => {
  // This fullOrder contains history dependent state. It is specific
  // to this one `merge` call and does not survive it.
  const fullCompare = makeFullOrderComparatorKit().antiComparator;

  const xs = windowResort(xelements, compareAntiRank, fullCompare);
  const ys = windowResort(yelements, compareAntiRank, fullCompare);
  return harden({
    [Symbol.iterator]: () => {
      // These four `let` variables are buffering one ahead from the underlying
      // iterators. Each iteration reports one or the other or both, and
      // then refills the buffers of those it advanced.
      /** @type {T} */
      let x;
      let xDone;
      /** @type {T} */
      let y;
      let yDone;

      const xi = xs[Symbol.iterator]();
      const nextX = () => {
        !xDone || Fail`Internal: nextX should not be called once done`;
        ({ done: xDone, value: x } = xi.next());
      };
      nextX();

      const yi = ys[Symbol.iterator]();
      const nextY = () => {
        !yDone || Fail`Internal: nextY should not be called once done`;
        ({ done: yDone, value: y } = yi.next());
      };
      nextY();

      return harden({
        next: () => {
          /** @type {boolean} */
          let done = false;
          /** @type {[T,bigint,bigint]} */
          let value;
          if (xDone && yDone) {
            done = true;
            // @ts-expect-error Because the terminating value does not matter
            value = [null, 0n, 0n];
          } else if (xDone) {
            // only ys are left
            value = [y, 0n, 1n];
            nextY();
          } else if (yDone) {
            // only xs are left
            value = [x, 1n, 0n];
            nextX();
          } else {
            const comp = fullCompare(x, y);
            if (comp === 0) {
              // x and y are equivalent, so report both
              value = [x, 1n, 1n];
              nextX();
              nextY();
            } else if (comp < 0) {
              // x is earlier, so report it
              value = [x, 1n, 0n];
              nextX();
            } else {
              // y is earlier, so report it
              comp > 0 || Fail`Internal: Unexpected comp ${q(comp)}`;
              value = [y, 0n, 1n];
              nextY();
            }
          }
          return harden({ done, value });
        },
      });
    },
  });
}
Returns an iterable whose iteration results are [key, xCount, yCount] tuples
representing the next key in the local full order, as well as how many
times it occurred in the x input iterator and the y input iterator.

For sets, these counts are always 0 or 1, but this representation
generalizes nicely for bags.

@template {Passable} T
@param {T[]} xelements
@param {T[]} yelements
@returns {Iterable<[T,bigint,bigint]>}