Functional programming in PHP
Almost a year ago Igor Wiedler wrote three articles on his blog about the state of functional programming in PHP.
The first article explores iteration. You'll learn to turn this
$admins = [];
foreach ($users as $user) {
if (is_admin($user)) {
$admins[] = $user;
}
}
into this
use function iter\filter;
$admins = filter('project\user\is_admin', $users);
In the second one he explains a very nice way to traverse an associative array. How you currently do it:
$baz = (isset($data['foo']['bar']['baz'])) ? $data['foo']['bar']['baz'] : null;
How you'll do it in the future:
use function igorw\get_in;
$baz = get_in($data, ['foo', 'bar', 'baz']);
The final article shows you a nice syntax to handle objects that return null-values.
All the articles mention libraries that you can use in your code today.
What are your thoughts on "Functional programming in PHP"?