-
-
Save Xion/5073416 to your computer and use it in GitHub Desktop.
Chained list operations in Python
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 L(object): | |
def __init__(self, iterable): | |
self.value = iterable | |
def map(self, fn): | |
self.value = map(fn, self.value) | |
return self | |
def join(self, s): | |
self.value = s.join(self.value) | |
return self | |
# that doesn't delegate every mechanic to self.value, | |
# do we need to implement every __special_method__?... | |
def __coerce__(self, other): | |
return type(other)(self.value) | |
# presumed usage: | |
L(some_List).map(some_function).join("some string") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment