<?php

namespace Planaday\Utility\DataGrouping;

use ArrayAccess;
use Countable;
use Traversable;

/**
 * @template TKey
 * @template TValue
 */
interface LazyFetchModifiable {

	/**
	 * Adds a callback that can be used to modify values as they are loaded
	 *
	 * @param callable(TValue): ?TValue $fetchAction the callback that will get called when a new value is fetched
	 * the return value of the callback will be used as the new value
	 * @param bool $applyRetroactively
	 *
	 * @return self
	 */
	public function addFetchAction(callable $fetchAction, bool $applyRetroactively = false): self;

	/**
	 * @return ArrayAccess<TKey, TValue>&Traversable<TKey, TValue>&Countable
	 */
	public function getLoadedValues(): ArrayAccess&Traversable&Countable;
}