préparation ajout Cursor::cols

This commit is contained in:
Jephté Clain 2025-02-04 09:07:08 +04:00
parent 4cce1c5598
commit 1c8d0a053e
1 changed files with 21 additions and 2 deletions

View File

@ -11,9 +11,20 @@ use Traversable;
* Class Cursor: parcours des lignes itérable
*
* @property-read array|null $value alias pour $row
* @property-read iterable|null $rows
* @property-read iterable|null $rows la source des lignes
*/
class Cursor implements Iterator {
const PARAMS_SCHEMA = [
"rows" => ["?iterable"],
"rows_func" => ["?callable"],
"cols" => ["?array"],
"cols_func" => ["?callable"],
"map" => ["?array"],
"map_func" => ["?callable"],
"filter" => ["?array"],
"filter_func" => ["?callable"],
];
/**
* mapper le tableau source $row selon les règles suivantes illustrées dans
* l'exemple suivant:
@ -129,15 +140,22 @@ class Cursor implements Iterator {
/** un générateur de lignes */
private ?Traversable $rowsGenerator;
/** une fonction qui retourne une instance de {@link iterable} */
/** une fonction de signature <code>function(Cursor):?iterable</code> */
private ?func $rowsFunc;
/** une fonction de signature <code>function(Cursor):?array</code> */
private ?func $colsFunc;
/** une fonction de signature <code>function(Cursor):?array</code> */
private ?func $mapFunc;
/** une fonction de signature <code>function(Cursor):bool</code> */
private ?func $filterFunc;
protected ?iterable $rows;
public ?array $cols;
public int $index;
public int $origIndex;
@ -185,6 +203,7 @@ class Cursor implements Iterator {
$map = $this->mapFunc;
while ($valid = iter::valid($this->rows)) {
$this->raw = iter::current($this->rows, $this->key);
$this->key ??= $this->origIndex;
$this->row = cl::withn($this->raw);
if ($filter === null) $filtered = $this->filter();
else $filtered = $filter->invoke([$this]);