"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "createUniqueSet", {
    enumerable: true,
    get: function() {
        return createUniqueSet;
    }
});
const _function = require("../../helpers/function");
const _errors = require("../../helpers/errors");
const DEFAULT_ERROR_ITEM_EXISTS = (item)=>`'${item}' value is already declared in a unique set.`;
function createUniqueSet({ errorItemExists } = {}) {
    const uniqueSet = new Set();
    errorItemExists = (0, _function.isFunction)(errorItemExists) ? errorItemExists : DEFAULT_ERROR_ITEM_EXISTS;
    /**
   * Adds items to the unique set. Throws an error if `item` is already added.
   *
   * @param {*} item The adding item.
   */ function addItem(item) {
        if (uniqueSet.has(item)) {
            (0, _errors.throwWithCause)(errorItemExists(item));
        }
        uniqueSet.add(item);
    }
    /**
   * Gets items from the set in order of addition.
   *
   * @returns {*}
   */ function getItems() {
        return [
            ...uniqueSet
        ];
    }
    /**
   * Clears the unique set.
   */ function clear() {
        uniqueSet.clear();
    }
    return {
        addItem,
        clear,
        getItems
    };
}
