Skip to content

Instantly share code, notes, and snippets.

@vanclist
Last active March 31, 2017 16:23
Show Gist options
  • Save vanclist/e2ea09eab70455ae54033a7b5fab452e to your computer and use it in GitHub Desktop.
Save vanclist/e2ea09eab70455ae54033a7b5fab452e to your computer and use it in GitHub Desktop.
class Mappable:
def __init__(self, items): self.items = items
def map(self, func):
return self.__class__(map(func, self.items))
class Filterable:
def __init__(self, items): self.items = items
def filter(self, func):
return self.__class__(filter(func, self.items))
class Hosts(object, Mappable, Filterable):
def __init__(self, items):
super(Hosts, self).__init__()
self.items = items
hosts = Hosts(["one", "two", 1337])
print hosts\
.filter(lambda x: type(x) == str)\
.filter(lambda x: not x.startswith("one"))\
.map(lambda x: {x: x*2})\
.items
print hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment