import { compR } from "./compr.js";
import { __iter } from "./iterator.js";
function distinct(...args) {
  return __iter(distinct, args) || ((rfn) => {
    const r = rfn[2];
    const opts = args[0] || {};
    const key = opts.key;
    const seen = (opts.cache || (() => /* @__PURE__ */ new Set()))();
    return compR(
      rfn,
      key ? (acc, x) => {
        const k = key(x);
        return !seen.has(k) ? (seen.add(k), r(acc, x)) : acc;
      } : (acc, x) => !seen.has(x) ? (seen.add(x), r(acc, x)) : acc
    );
  });
}
export {
  distinct
};
