PHP code example of jotaelesalinas / php-mapreduce
1. Go to this page and download the library: Download jotaelesalinas/php-mapreduce library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jotaelesalinas / php-mapreduce example snippets
declare(strict_types=1);
use JLSalinas\SimpleMapReduce\MapReduce;
$result = MapReduce::create()
->input([1, 2, 3, 4, 5])
->map(static fn (mixed $item): mixed => $item * 2)
->reduce(static fn (mixed $carry, mixed $item): mixed => ($carry ?? 0) + $item)
->run();
var_dump($result);
$doublerFn = static fn (mixed $item): mixed => $item * 2;
final class Stats
{
public static function max(?int $carry, int $item): int
{
return $carry === null
? $item
: max($carry, $item);
}
}
$result = MapReduce::create()
->input([1, 2, 3, 4, 5])
->map($doublerFn)
->reduce([Stats::class, 'max'])
->run();
$result = MapReduce::create()
->input($items)
->filterInput($inputFilter)
->map($mapper)
->groupBy($groupBy)
->filterMapped($mappedFilter)
->reduce($reducer)
->progress($progressCallback)
->output($writer)
->run();
use JLSalinas\MapReduce\MapReduce;
use JLSalinas\SimpleMapReduce\MapReduce;
MapReduce::create()
->input($items)
->map($mapper)
->reduce($reducer)
->run();
bash
composer bash
composer install
php examples/pets.php
php examples/insurance.php
php examples/benchmark-big-dataset.php
bash
composer remove jotaelesalinas/php-mapreduce
composer