guglielmopepe / recursivecallbackmapiterator
This iterator applies recursively the callback to the elements of the given iterator.
Requires
- php: ^7.2.0 || ^8.0.0
README
This iterator applies recursively the callback to the elements of the given iterator.
Table of Contents
Installation
Use Composer
$ composer require guglielmopepe/recursivecallbackmapiterator
Usage
The callback should accept up to three arguments: the current item, the current key and the iterator, respectively.
<?php /** * Callback for RecursiveCallbackMapIterator * * @param $current Current item's value * @param $key Current item's key * @param $iterator Iterator being filtered * @return mixed The item after it has been applied the callback function */ function my_callback($current, $key, $iterator) { // Your code here } ?>
Any callable may be used; such as a string containing a function name, an array for a method, or an anonymous function.
<?php $data = ['foo'=>['foo','bar'],'bar'=>['bar','foo']]; // A callback function my_callback($current, $key, $iterator) { if ($key % 2 == 0) { return $current; } return \strtoupper($current); } // Applies callback $iterator = new \RecursiveCallbackMapIterator\RecursiveCallbackMapIterator(new \RecursiveArrayIterator($data), 'my_callback'); ?>
Support
If you have a request, please create a GitHub issue.
If you discover a security vulnerability, please send an email to Guglielmo Pepe at info@guglielmopepe.com. All security vulnerabilities will be promptly addressed.
Contributing
If you want to say thank you and/or support the active development of RecursiveCallbackMapIterator
:
- Add a GitHub Star to the project.
- Share the project on social media.
- Write a review or tutorial on Medium, Dev.to or personal blog.
Contacts
If you need information please send an email to info@guglielmopepe.com.
Roadmap
See the list of open issues:
Change log
Please see Changelog file for more information on what has changed recently.
License
Distributed under the MIT License. Please see License File for more information.