Skip to content

Instantly share code, notes, and snippets.

@victorusachev
Created September 19, 2019 22:00
Show Gist options
  • Select an option

  • Save victorusachev/eeff254122cf03962a2a9d0073f1871b to your computer and use it in GitHub Desktop.

Select an option

Save victorusachev/eeff254122cf03962a2a9d0073f1871b to your computer and use it in GitHub Desktop.
class List:
def __init__(self, items):
super().__init__()
self._items = items
def __call__(self, function):
self._items = map(function, self)
return self
def __iter__(self):
return iter(self._items)
@property
def result(self):
self._items = tuple(self._items)
return self._items
def main(data, functions):
functor = List(data)
for func in functions:
functor = functor(func)
yield functor.result
if __name__ == '__main__':
stages = main(
data=(-2, -1, 0, 1, 2, 21),
functions=(abs, float, str, reversed, list, ''.join, float)
)
for stage in stages:
print(stage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment