diff --git a/src/php/coll/Cursor.php b/src/php/coll/Cursor.php index 884f449..f1ec9d9 100644 --- a/src/php/coll/Cursor.php +++ b/src/php/coll/Cursor.php @@ -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 function(Cursor):?iterable */ private ?func $rowsFunc; + /** une fonction de signature function(Cursor):?array */ + private ?func $colsFunc; + + /** une fonction de signature function(Cursor):?array */ private ?func $mapFunc; + /** une fonction de signature function(Cursor):bool */ 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]);