Skip to content

[Idea] Implement using Iterators instead of arrays #1

Description

@lovenunu

Hello,

I think we can save some time and memory on large data sets by using iterators instead of arrays here:
https://github.com/functional-php/parallel/blob/master/src/functions.php#L75

If we provide an iterator (from a DB statement for example), we have to traverse it once in the iterator_to_array statement, then array_chunk make use traverse the data set once more.

Using iterators will not be a problem with array, as we already have \ArrayIterator class in SPL.

Moreover, instead of traversing two arrays here: https://github.com/functional-php/parallel/blob/master/src/functions.php#L59 , we could only traverse it once and apply the two functions in the same time.

BTW, a major part of the problem has already been solved in this (great) lib from nikic: https://github.com/nikic/iter/ (chunk, map and filter).

In the worst case, we could save 3 of 4 iterations. :-)

What do you think of this idea ? :-)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions