Last active
October 17, 2018 08:26
-
-
Save genya0407/f8085dbc07073bf1e21247bffb0cb037 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 ri(object): | |
def __init__(self, arraylike): | |
self.data = arraylike | |
def to_a(self): | |
return list(self.data) | |
def map(self, func): | |
return ri(map(func, self.data)) | |
def filter(self, func): | |
return ri(filter(func, self.data)) | |
def each(self, func): | |
self.map(func).to_a() | |
if __NAME__ == '__MAIN__': | |
result = ri([1,2,3,4,5]).map(lambda x: x*3).filter(lambda x: x < 10).to_a() | |
print(result) # => [3, 6, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment