Comments (2)
Hi @Danon,
Thanks for your kind words and interest in IterTools PHP.
For zipping iterables that are different sizes, I think you can make a good argument for both throwing exceptions and iterating as much as you can. The behavior that the library has for zip
is to iterate up until the point that the shortest input iterable is exhausted. Python's built-in zip
function was the original inspiration for this library--I wanted something similar in PHP. So for IterTools PHP's zip
function, I went with Python's behavior because it is well known and provides the most flexibility in how you can use it. Also, each use case is different. For the cases where this is not desirable, the application code could simply check the input sizes prior to zipping and throw the exception there.
FYI: Here is how Python works zipping iterables of different sizes:
>>> for x, y in zip([1, 2, 3], ['a', 'b']):
... print(x, y)
...
1 a
2 b
>>> for x, y in zip([1, 2], ['a', 'b', 'c']):
... print(x, y)
...
1 a
2 b
The library also provides a Multi::zipLongest
function that will iterate every element of the largest iterable if one has more than another, providing null values for the iterables that run out of data. So there are multiple ways to deal with zipping inputs of different sizes.
Thanks again for your interest in IterTools PHP!
Mark
from itertools-php.
You could design API in sucha a way:
Multi::zipLongest()
- assume different lengths - iterates with the higher of the iteratorsMulti::zipShortest()
- assume different lengths - iterates with the lower of the iteratorsMulti::zip()
- assumes equal iterators, throws exception otherwise
But of course, that's your library and your decision, so I'm not gonna push it, just asking.
To me, throwing exception is more natural, I rarely ever zip collections of different sizes, so I would prefer the exception. I'm leaving the decision to you.
from itertools-php.
Related Issues (6)
- How about iterating resources? HOT 7
- Docs translation HOT 18
- README fix about multiset rules HOT 5
- Pipe functionlity suggestion HOT 4
- New IterTools Functionality Discussion HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from itertools-php.