Property fetch
use Fp4PHP\ArrayList;
use function Fp4PHP\Combinator\pipe;
use const Fp4PHP\Combinator\accessor as it;
$persons = [
new Person(id: 1, name: 'person#1'),
new Person(id: 2, name: 'person#2'),
new Person(id: 3, name: 'person#3'),
];
// Shorthand version
$names = pipe($persons, ArrayList\map(it->name));
// Classic version
$names = pipe($persons, ArrayList\map(static fn (Person $p) => $p->name));
ArrayDimFetch
use Fp4PHP\ArrayList;
use function Fp4PHP\Combinator\pipe;
use const Fp4PHP\Combinator\accessor as it;
$persons = [
['id' => 1, 'name' => 'person#1'],
['id' => 2, 'name' => 'person#2'],
['id' => 3, 'name' => 'person#3'],
];
// Shorthand version
$names = pipe($persons, ArrayList\map(it['name']));
// Classic version
$names = pipe($persons, ArrayList\map(static fn (array $p) => $p['name']));
MethodCall
use Fp4PHP\ArrayList;
use function Fp4PHP\Combinator\pipe;
use const Fp4PHP\Combinator\accessor as it;
$persons = [
new Person(id: 1, name: 'person#1'),
new Person(id: 2, name: 'person#2'),
new Person(id: 3, name: 'person#3'),
];
// Shorthand version
$names = pipe(
$persons,
ArrayList\map(it->getName()),
);
// Classic version
$names = pipe(
$persons,
ArrayList\map(static fn (Person $p) => $p->getName()),
);
Reactions are currently unavailable