Last active
June 23, 2022 15:18
-
-
Save kyle-eshares/5b61c616c650e749dbac21355e522bb4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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