Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterable Composition object #559

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions toolz/functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ def __getstate__(self):
def __setstate__(self, state):
self.first, self.funcs = state

def __iter__(self):
for f in reversed(self.funcs): yield f
yield self.first

@instanceproperty(classval=__doc__)
def __doc__(self):
def composed_doc(*fs):
Expand All @@ -509,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.
Expand All @@ -519,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):
Expand Down