pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.57k stars 258 forks source link

iterable Composition object #559

Open ZeroBomb opened 1 year ago

ZeroBomb commented 1 year ago

I previously suggested that compositions should be iterable in issue https://github.com/pytoolz/toolz/issues/553

I decided to see what that would look like, and have included the code here. The change is pretty trivial (adding an __iter__ function to the Compose object) and I went ahead and simplified the __doc__, __name__, and __repr__ functions to take advantage of the fact that you can just use self as an iterable to remove reversed((first,)+funcs).

I don't know how your tests work, but it seems to work fine with all my code. The only way I can imagine this breaking anything is if the code ever checks for iterability to decide if something is a Compose object, but I didn't see anything like that.