Last active
March 31, 2017 16:23
-
-
Save vanclist/e2ea09eab70455ae54033a7b5fab452e to your computer and use it in GitHub Desktop.
This file contains 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 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