Map-Filter Combination in PHP
Following on from my discussion on Mapping, Filtering and Reducing in PHP, over the past couple of months I have been using a little trick I would like to discuss.
map-filter combination can be achieved in a single
reduce, reading the PHP documentation I found out that
array_filter supplied without a predicate function will remove all
false values from the collection.
This means that you can simply map over a collection and return
false if the desired predicate does not match - leaving the filter to do the clean-up.