rosavox/lib/alveolata/structures/map/wrapper-class.php

59 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2025-05-23 07:33:29 +00:00
<?php
namespace alveolata\structures;
require_once(DIR_ALVEOLATA . '/structures/map/functions.php');
/**
* @template type_key
* @template type_value
*/
class class_map
{
/**
* @var \Closure {function<type_key,type_key,boolean>}
*/
private $collate_key;
/**
* @var struct_subject_map<type_key,type_value>
*/
private $subject;
/**
* @param struct_subject_map<type_key,type_value>
*/
public function __construct(
\Closure $collate_key,
struct_subject_map $subject
)
{
$this->collate_key = $collate_key;
$this->subject = $subject;
}
/**
* @param array $pairs {list<&struct_subject_pair<§type_key,§type_value>>}
*/
public static function make(
\Closure $collate_key,
array $pairs = []
) : class_map
{
return (new class_map($collate_key, map_make($pairs)));
}
public function get($key) {return map_get($this->collate_key, $this->subject, $key);}
public function set($key, $value) : void {map_set($this->collate_key, $this->subject, $key, $value);}
public function iterate(\Closure $procedure) : void {map_iterate($this->subject, $procedure);}
}
?>