Last active
July 14, 2016 20:43
-
-
Save italolelis/2712c6c671b50864748b to your computer and use it in GitHub Desktop.
FlatMap implementation in PHP, following the Reactive Extensions intiative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flatMap($data, \Closure $p) | |
{ | |
$collection = call_user_func_array("array_map", array($p)); | |
return iterator_to_array(new \RecursiveIteratorIterator( | |
new \RecursiveArrayIterator($data)), false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is
$collection
doing?https://gist.github.com/italolelis/2712c6c671b50864748b#file-flatmap-php-L3
How could you deal with nested elements?
To obtain: