Functional Collection
Small functional multi-purpose collection, (*1)
, (*2)
Insall
composer require troublete/collection
Usage
<?php
use function TryPhp\collection;
$collection = collection([1, 2, 3]);
// or
use TryPhp\FuntionalCollection;
$collection = new FunctionalCollection([1, 2, 3]);
API
of(...$values)
Setup new collection with provided values. immutable, (*3)
map(callable $mapFunc)
Method which will be applied to each element in the value set of the collection. mutable, (*4)
filter(callable $predicate)
Method which will create a collection copy and filter values by function (returning false filters value out). immutable, (*5)
generator(): \Generator
Returns Generator over value set., (*6)
Will return value set., (*7)
extend(callable $func)
Method will call the provided Closure and inject set values. Returned values will be put into immutable FunctionalCollection and returned. immutable, (*8)
concat(FunctionaCollection $collection)
Method will combine to value sets of two collection and return a new one with set values. immutable, (*9)
chain(callable $map)
Method which will apply $map to every element in the value collection and will reduce the result and add it to the overall value set and create a immutable new collection with it. immutable, (*10)
reduce(callable $func = null)
Method to reduce the value set (value by value) according to the result of calling $func and return the created accumulated value. If $func is null the raw value is used and added to the accumulator., (*11)
License
GPL-2.0 © 2018 Willi Eßer, (*12)