From 0bfa009b7b108293ffebce67aa8dffce94acee30 Mon Sep 17 00:00:00 2001 From: ZeroBomb Date: Wed, 11 Jan 2023 20:52:04 -0600 Subject: [PATCH 1/2] add __iter__ function to Compose --- toolz/functoolz.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/toolz/functoolz.py b/toolz/functoolz.py index 2c75d3a4..b5708f2c 100644 --- a/toolz/functoolz.py +++ b/toolz/functoolz.py @@ -495,6 +495,10 @@ def __getstate__(self): def __setstate__(self, state): self.first, self.funcs = state + def __iter__(self): + yield self.first + for f in self.funcs: yield f + @instanceproperty(classval=__doc__) def __doc__(self): def composed_doc(*fs): From c89c33d94560cc6e6ff2c4c46b6fac691943e780 Mon Sep 17 00:00:00 2001 From: ZeroBomb Date: Wed, 11 Jan 2023 21:14:09 -0600 Subject: [PATCH 2/2] flip yield order to be consistent with other code --- toolz/functoolz.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toolz/functoolz.py b/toolz/functoolz.py index b5708f2c..9cd865ab 100644 --- a/toolz/functoolz.py +++ b/toolz/functoolz.py @@ -496,8 +496,8 @@ def __setstate__(self, state): self.first, self.funcs = state def __iter__(self): + for f in reversed(self.funcs): yield f yield self.first - for f in self.funcs: yield f @instanceproperty(classval=__doc__) def __doc__(self): @@ -513,7 +513,7 @@ def composed_doc(*fs): try: return ( 'lambda *args, **kwargs: ' + - composed_doc(*reversed((self.first,) + self.funcs)) + composed_doc(*self) ) except AttributeError: # One of our callables does not have a `__name__`, whatever. @@ -523,14 +523,14 @@ def composed_doc(*fs): def __name__(self): try: return '_of_'.join( - (f.__name__ for f in reversed((self.first,) + self.funcs)) + (f.__name__ for f in self) ) except AttributeError: return type(self).__name__ def __repr__(self): return '{.__class__.__name__}{!r}'.format( - self, tuple(reversed((self.first, ) + self.funcs))) + self, tuple(self)) def __eq__(self, other): if isinstance(other, Compose):