44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace alveolata\structures;
|
||
|
|
||
|
require_once(DIR_ALVEOLATA . '/structures/list/functions.php');
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @template type_element
|
||
|
*/
|
||
|
class class_list
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @var struct_subject_list<type_element>
|
||
|
*/
|
||
|
private $subject;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param struct_subject_list<type_element>
|
||
|
*/
|
||
|
public function __construct(struct_subject_list $subject) {$this->subject = $subject;}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param array $elements {list<§element>}
|
||
|
*/
|
||
|
public static function make(array $elements = []) {return (new class_list(list_make($elements)));}
|
||
|
|
||
|
|
||
|
public function length() : int {return list_length($this->subject);}
|
||
|
public function get($index) {return list_get($this->subject, $index);}
|
||
|
public function add($element) : void {list_add($this->subject, $element);}
|
||
|
public function iterate(\Closure $procedure) : void {list_iterate($this->subject, $procedure);}
|
||
|
public function filter(\Closure $predicate) : class_list {return (new class_list(list_filter($this->subject, $predicate)));}
|
||
|
public function map(\Closure $transformation) : class_list {return (new class_list(list_map($this->subject, $transformation)));}
|
||
|
public function reduce($start, \Closure $aggregation) {return list_reduce($this->subject, $start, $aggregation);}
|
||
|
public function collate(\Closure $collate_element, class_list $other) {return list_collate($collate_element, $this->subject, $other);}
|
||
|
|
||
|
}
|
||
|
|
||
|
?>
|