PHP code example of pitchart / collection
1. Go to this page and download the library: Download pitchart/collection 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/ */
pitchart / collection example snippets
use Pitchart\Collection\Collection;
$numbers = Collection::from([1, 2, 3, 4]);
$plusOneNumbers = $numbers->map(function ($item) {
return $item + 1;
});
$evenNumbers = $plusOneNumbers->filter(function ($item) {
return $item % 2 == 0;
});
$total = $evenNumbers->reduce(function ($accumulator, $item) {
return $accumulator + $item;
}, 0);
$total = Collection::from([1, 2, 3, 4])
->map(function ($item) {
return $item + 1;
})
->filter(function ($item) {
return $item % 2 == 0;
})
->reduce(function ($accumulator, $item) {
return $accumulator + $item;
}, 0);
use Pitchart\Collection\GeneratorCollection;
$collection = Collection::from($heavyFolderList)
->map(function ($folder) {
return loadContentFromFilesInFolder($folder);
})
->filter(function ($content) {
return lotsOfRegexpContentFiltering($content);
})
->reduce(function ($accumulator, $content) {
return $accumulator.retrievePartsToCollect($content);
}, '');
/** @var Collection $reusableCollection */
$reusableCollection = $generatorCollection->persist();
use function Pitchart\Collection\Helpers\map;
map([1, 2, 3, 4], function ($item) {
return $item + 1;
})
->filter(function ($item) {
return $item % 2 == 0;
});