-
-
Save okeyokoro/a0d2b2aa4eaf816a8bae13d31ce672e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class conduit(object): | |
def __init__(self, iterator): | |
self.iterator = iterator | |
def filter(self, predicate): | |
return conduit(itertools.ifilter(predicate, self.iterator)) | |
def map(self, func): | |
return conduit(itertools.imap(func, self.iterator)) | |
def sort(self, key): | |
# sort has to evaluate the iterator | |
return conduit(sorted(self.iterator, key=key)) | |
def __iter__(self): | |
return iter(self.iterator) | |
def to_list(self): | |
return list(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment