Skip to content

Instantly share code, notes, and snippets.

@genya0407
Last active October 17, 2018 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genya0407/f8085dbc07073bf1e21247bffb0cb037 to your computer and use it in GitHub Desktop.
Save genya0407/f8085dbc07073bf1e21247bffb0cb037 to your computer and use it in GitHub Desktop.
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