19 declare(strict_types=1);
32 private readonly array $map = [],
36 public function add(
string $name, $item): static
38 return $this->
map($name, fn($list) => [...$list, $item]);
41 public function set(
string $name,
string $key, $item):
static 43 return $this->
map($name, fn(array $map) => [...$map, $key => $item]);
46 public function has(
string $name,
string $key): bool
48 return isset($this->
map[$name][$key]);
51 public function append(
self $other): self
56 if (count($mine) + count($other) !== count(array_merge($mine, $other))) {
57 throw new Exception(
'Cannot append maps. Keys must be distinct.');
59 }, $this->map, $other->value());
60 return new self(array_merge_recursive($this->
map, $other->value()));
73 return new self([...$this->map, $key => $proc($this->
map[$key] ?? [])]);
__construct(private readonly array $map=[],)
map(string $key, Closure $proc)
has(string $name, string $key)