markrogoyski / itertools-php

PHP Iteration Tools Library
MIT License
140 stars 11 forks source link

Method Multi::zipStrict() added #5

Closed Smoren closed 1 year ago

Smoren commented 1 year ago

Hi! I was thinking about the details of Reduce::exactlyN() method implementation.

To solve this task I need to check that all the given iterables are equals both by their lengths and by their values.

But when I use Multi::zipLongest(), I have nulls on last iterations when given iterators have different lengths. So I don't know if some iterators are ended or contain nulls in their tails.

The best solution I have found was to add method Multi::zipStrict() which throws OutOfRangeException when lengths of given iterators are not the same.

Here is the summary of this pull request:

  1. Method Multi::zipStrict() added.
  2. Class Utilities\StrictMultipleIterator added.
  3. Tests for new method added (coverage 100%).
  4. README.md updated with new method's description.

I hope you find this functionality useful.

coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 3793473822

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 2224581354: 0.3%
Covered Lines: 177
Relevant Lines: 178

💛 - Coveralls
Smoren commented 1 year ago

There is Reduce::exactlyN() implementation in my separate branch: https://github.com/Smoren/itertools-php/blob/reduce_exactly_n/src/Reduce.php#L188 I can make another pull request for it if you want.

markrogoyski commented 1 year ago

Hi @Smoren,

Thank you again for another pull request. I left a couple suggestions in the comments.

Mark

Smoren commented 1 year ago

Hi @markrogoyski!

All your suggestions are applied.

  1. Method Multi::zipStrict() renamed to Multi::zipEqual().
  2. \OutOfRangeException replaced with \LengthException.
markrogoyski commented 1 year ago

Thank you @Smoren for the pull request. This will go out with the next release.

Smoren commented 1 year ago

Thank you Mark!

Smoren commented 1 year ago

@markrogoyski

By the way, I would be glad to hear your opinion about my repository, which is also inspired by python and implements the functionality of iterable sequences for PHP.

If you can find time for this, I will be very grateful.

https://github.com/Smoren/sequence-php

markrogoyski commented 1 year ago

Hi @Smoren,

Thanks for sharing the link to your sequence library.

Just one suggestion: Since PHP has a built-in range function, it might be helpful to compare and contrast your xrange and Range with PHP's range so the reader knows why they might want to chose one over the other.

Smoren commented 1 year ago

Hi @markrogoyski

Thank you for your feedback!

I've added more descriptions to the README file, including one on the difference between xrange and range.

However the README is designed as you have in IterTools now.