"use strict";

// FIXME: Publish as separate non-modular-matrix package

module.exports = function createItemDeduplicator(getKey) {
	let items = new Map();

	return function deduplicateItem(item) {
		let key = getKey(item);

		if (key == null) {
			// We cannot deduplicate an item that doesn't have a key
			return item;
		} else if (items.has(key)) {
			return items.get(key);
		} else {
			items.set(key, item);
			return item;
		}
	};
};
