préparation ajout Cursor::cols
This commit is contained in:
parent
4cce1c5598
commit
1c8d0a053e
|
@ -11,9 +11,20 @@ use Traversable;
|
||||||
* Class Cursor: parcours des lignes itérable
|
* Class Cursor: parcours des lignes itérable
|
||||||
*
|
*
|
||||||
* @property-read array|null $value alias pour $row
|
* @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 {
|
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
|
* mapper le tableau source $row selon les règles suivantes illustrées dans
|
||||||
* l'exemple suivant:
|
* l'exemple suivant:
|
||||||
|
@ -129,15 +140,22 @@ class Cursor implements Iterator {
|
||||||
/** un générateur de lignes */
|
/** un générateur de lignes */
|
||||||
private ?Traversable $rowsGenerator;
|
private ?Traversable $rowsGenerator;
|
||||||
|
|
||||||
/** une fonction qui retourne une instance de {@link iterable} */
|
/** une fonction de signature <code>function(Cursor):?iterable</code> */
|
||||||
private ?func $rowsFunc;
|
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;
|
private ?func $mapFunc;
|
||||||
|
|
||||||
|
/** une fonction de signature <code>function(Cursor):bool</code> */
|
||||||
private ?func $filterFunc;
|
private ?func $filterFunc;
|
||||||
|
|
||||||
protected ?iterable $rows;
|
protected ?iterable $rows;
|
||||||
|
|
||||||
|
public ?array $cols;
|
||||||
|
|
||||||
public int $index;
|
public int $index;
|
||||||
|
|
||||||
public int $origIndex;
|
public int $origIndex;
|
||||||
|
@ -185,6 +203,7 @@ class Cursor implements Iterator {
|
||||||
$map = $this->mapFunc;
|
$map = $this->mapFunc;
|
||||||
while ($valid = iter::valid($this->rows)) {
|
while ($valid = iter::valid($this->rows)) {
|
||||||
$this->raw = iter::current($this->rows, $this->key);
|
$this->raw = iter::current($this->rows, $this->key);
|
||||||
|
$this->key ??= $this->origIndex;
|
||||||
$this->row = cl::withn($this->raw);
|
$this->row = cl::withn($this->raw);
|
||||||
if ($filter === null) $filtered = $this->filter();
|
if ($filter === null) $filtered = $this->filter();
|
||||||
else $filtered = $filter->invoke([$this]);
|
else $filtered = $filter->invoke([$this]);
|
||||||
|
|
Loading…
Reference in New Issue