Is large use of closures actually a bad thing for readability and maintainability of the code? For example, consider the following code with (comments removed on purpose):
$withMobile = function($c) { return $c->getMobile() !== null; };
$extractAll = function($c) { return $c; };
$extractId = function($c) { return $c->getId(); };
$allUniqueCustomers = $data->customers->filter($withMobile)->map($extractAll);
$customersIds = $allUniqueCustomers->filter($withMobile)->map($extractId)->toArray();
$isNew = function($c) use($customersIds) { return !in_array($c->getId(), $customersIds); };
foreach($data->tags as $tag) :
foreach($tag->getCustomers()->filter($isNew)->filter($withMobile) as $newCustomer) :
$allUniqueCustomers->add($newCustomer);
endforeach;
endforeach;
$sanitize = function($m) { return preg_replace("/^(\+|00)/", '', $m); };
$extractMobile = function($c) use($sanitize) { return $sanitize($c->getMobile()); };
// Unique sanitized phone numbers of customers merged with customers from tags
$customersMobiles = $allUniqueCustomers->map($extractMobile);
It looks good to me. But i love closures.
Would you consider this a nightmare to maintain and change in future in respect of traditional more verbose programming with loops?