Skip to content

Instantly share code, notes, and snippets.

@Xion
Last active December 22, 2021 23:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xion/5073416 to your computer and use it in GitHub Desktop.
Save Xion/5073416 to your computer and use it in GitHub Desktop.
Chained list operations in Python
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