Map Process
Map with stateful variables
productName | dollar_sales |
---|---|
1937 Lincoln Berline | 3726.45 |
1936 Mercedes-Benz 500K Special Roadster | 1768.33 |
1952 Alpine Renault 1300 | 5571.8 |
1962 LanciaA Delta 16V | 5026.14 |
1958 Setra Bus | 3284.28 |
1940 Ford Pickup Truck | 3307.5 |
1926 Ford Fire Engine | 1283.48 |
1913 Ford Model T Speedster | 2489.13 |
1934 Ford V8 Coupe | 2164.4 |
18th Century Vintage Horse Carriage | 2173 |
$mapState = ['rest_sales' => 0];
...
->pipe(new Map(array(
->pipe(new Map([
'{value}' => function ($row, $meta, $index) use (&$mapState) {
if ($index >= 5) {
$mapState['rest_sales'] = $mapState['rest_sales'] + 1 * $row['dollar_sales'];
return null;
} else {
return $row;
}
},
'{end}' => function ($count) use (&$mapState) {
$rowToSend = [
'productName' => 'The rest products: ',
'dollar_sales' => $mapState['rest_sales']
];
return $rowToSend;
},
]))
)))
productName | dollar_sales |
---|---|
1937 Lincoln Berline | 3726.45 |
1936 Mercedes-Benz 500K Special Roadster | 1768.33 |
1952 Alpine Renault 1300 | 5571.8 |
1962 LanciaA Delta 16V | 5026.14 |
1958 Setra Bus | 3284.28 |
The rest products: | 11417.51 |
What People Are Saying
"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
--
Alain Melsens
"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
--
Dr. Lew Choy Onn
"Fantastic framework for reporting!"
--
Greg Schneider