A package that provides `array_*` like functions for iterators.

Overview

Iterator functions

Latest Version on Packagist Tests

The doekenorg/iterator-functions package provides a curated set of array_* like functions for iterators in PHP. This package is built to encourage developers to make more use of Iterators by simplifying common tasks.

Available functions

All available functions are modeled after their array_* equivalent. But instead of returning an array it will return an Iterator instance. This means that you can use them in the same way, but get the added memory preserving benefits.

  • iterator_column(\Traversable $iterator, $column_key, $index_key = null): ColumnIterator
  • iterator_filter(Iterator $iterator, ?callable $callback = null): \CallbackFilterIterator
  • iterator_flip(Iterator $iterator): FlipIterator
  • iterator_keys(\Iterator $iterator): KeysIterator
  • iterator_map(callable $callback, iterable ...$iterators): MapIterator
  • iterator_reduce(\Iterator $iterator, callable $callback, $initial = null)
  • iterator_values(\Iterator $iterator): ValuesIterator
  • iterator_walk(\Iterator $iterator, callable $callback, ...$arguments): void

Note: There are no _diff or _intersect functions available, because these are not possible without forgoing on the memory benefits of iterators.

Available iterators

Where possible the functions make use of native iterators. Any missing iterators were added to this package.

  • ColumnIterator - Iterator that returns a single column for the iteration array / object.
  • FlipIterator - Iterator that flips the key and the value of the current iteration.
  • KeysIterator - Iterator that returns only the keys of the provided iterator.
  • MapIterator - Iterator that applies a callback to the elements of the given iterators.
  • ValuesIterator - Iterator that returns only the values of the provided iterator.

Install

You can install the package via composer:

composer require doekenorg/iterator-functions

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

./vendor/bin/pest

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A redacted PHP port of Underscore.js with additional functions and goodies – Available for Composer and Laravel

Underscore.php The PHP manipulation toolbelt First off : Underscore.php is not a PHP port of Underscore.js (well ok I mean it was at first). It's does

Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

All PHP functions, rewritten to throw exceptions instead of returning false

Safe PHP This project is deprecated Because of how this project needs to be in sync with the official PHP documentation, maintaining a set of function

All PHP functions, rewritten to throw exceptions instead of returning false, now for php8

A set of core PHP functions rewritten to throw exceptions instead of returning false when an error is encountered.

Adds factory functions for WooCommerce to be used with wp-browser integration tests.

wp-browser-woocommerce This library simplifies testing of WooCommerce themes and plugins with wp-browser. Several Unit Test Factories are added that a

A collection of functions to clean up WordPress

Clean WordPress Admin A collection of functions to clean up WordPress front and back-end to make it easier for editors to work and for you to look at

Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

just the most basic functions of the website.

cybergrungewebsite just the most basic functions of the website. upload handling the artists folder contains custom upload.php which handles uploads.

This is a simple Wrapper around the ZipArchive methods with some handy functions

Note I haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5. I archived the repository

Comments
  • Adds `iterator_diff_` and `iterator_intersect_` functions

    Adds `iterator_diff_` and `iterator_intersect_` functions

    Unlike stated in the README it can be possible to implement _diff and _intersect functions by repeatedly looping of the provided iterators. Because this is probably not the most performant check, for now this PR is mostly an experiment. It remains to be seen if it will be released.

    This PR tries to implement the following functions:

    • iterator_diff
    • iterator_diff_assoc
    • iterator_diff_key
    • iterator_diff_uassoc
    • iterator_diff_ukey
    • iterator_udiff
    • iterator_udiff_assoc
    • iterator_udiff_uassoc
    • iterator_intersect
    • iterator_intersect_assoc
    • iterator_intersect_key
    • iterator_intersect_uassoc
    • iterator_intersect_ukey
    • iterator_uintersect
    • iterator_uintersect_assoc
    • iterator_uintersect_uassoc

    Todo:

    • [x] Clean up code
    • [x] Add argument checks and exceptions
    • [x] Add tests for checks and exceptions
    • [x] Test for Iterators directly
    research 
    opened by doekenorg 1
  • Support for iterable-agnostic functions

    Support for iterable-agnostic functions

    Nice package! So annoying that PHP doesn't provide this logic in their standard libs. However, even with these functions i still have to type check before calling them: $iterable instanceof \Traversable ? iterator_xxx : array_xxx. Would be epic if agnostic variants where introduced (e.g. iterable_map, iterable_keys, iterable_flip. Then you could just pas an iterable and the function would do the rest. I think they should return what they where fed so array if is_array($iterable), otherwise \Traversable.

    enhancement 
    opened by sjadema 2
Releases(v1.0.1)
Owner
Doeke Norg
Doeke Norg
Magento-Functions - A Resource of Magento Functions

Magento-Functions A Resource of Magento Functions Table of Contents Category Product User Cart Checkout General Account [Working w/ URL's] (#urls) Cat

Bryan Littlefield 28 Apr 19, 2021
Here is the top 100 PHP functions: it is the list of the most often used PHP native functions

Here is the top 100 PHP functions: it is the list of the most often used PHP native functions. If you are a PHP developer, you must know the Top 100 PHP Functions deeply.

Max Base 16 Dec 11, 2022
This component provides a collection of functions/classes using the symfony/intl package when the Intl extension is not installed.

Symfony Polyfill / Intl: ICU This package provides fallback implementations when the Intl extension is not installed. It is limited to the "en" locale

Symfony 2.4k Jan 6, 2023
PHP package that provides functions for calculating mathematical statistics of numeric data

Statistics PHP package PHP package that provides functions for calculating mathematical statistics of numeric data. In this package I'm collecting som

Hi Folks! 289 Dec 27, 2022
PHP package that provides functions for calculating mathematical statistics of numeric data.

Statistics PHP package PHP package that provides functions for calculating mathematical statistics of numeric data. In this package I'm collecting som

Hi Folks! 290 Dec 29, 2022
This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions

This project backports features found in the latest PHP versions and provides compatibility layers for some extensions and functions. It is intended to be used when portability across PHP versions and extensions is desired.

Symfony 2.2k Dec 29, 2022
This component provides functions unavailable in releases prior to PHP 8.0.

This component provides functions unavailable in releases prior to PHP 8.0.

Symfony 1.5k Dec 29, 2022
This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube features.

Laravel Youtube Client This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube featu

Tilson Mateus 6 May 31, 2023
A utility package that helps inspect functions in PHP.

A utility package that helps inspect functions in PHP. This package provides some utilities for inspecting functions (callables) in PHP. You can use i

Ryan Chandler 14 May 24, 2022
Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways like sslcommerz, greenweb, dianahost,metronet in Laravel framework

Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways for Laravel. You should use

Ariful Islam 95 Jan 3, 2023