CKTIS / PHP
Data processing pipelines
Connect a producer, validator and consumer with iterable inputs.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
function stage(iterable $input): Generator { foreach ($input as $v) { yield $v; } }Connect a producer, validator and consumer with iterable inputs. A generator stage pulls records only when the consumer requests them, so an early break leaves later source records unread. Skip malformed records explicitly before conversion to keep them distinct from a valid zero.
function rows(&$seen){foreach(["x","0","8"] as $v){$seen[]=$v;yield $v;}}function numbers(iterable $rows){foreach($rows as $r){if(ctype_digit($r))yield (int)$r;}}
$seen=[];foreach(numbers(rows($seen)) as $n){echo $n," ";break;}echo json_encode($seen);
0 ["x","0"]
Examples
<?php
function rows(&$seen){foreach(["x","0","8"] as $v){$seen[]=$v;yield $v;}}function numbers(iterable $rows){foreach($rows as $r){if(ctype_digit($r))yield (int)$r;}}
$seen=[];foreach(numbers(rows($seen)) as $n){echo $n," ";break;}echo json_encode($seen);
Result
0 ["x","0"]