Skip to content

Instantly share code, notes, and snippets.

@fabiocerqueira
Last active February 6, 2018 22:56
Show Gist options
  • Select an option

  • Save fabiocerqueira/66ece5d16186519299ba326082001fc9 to your computer and use it in GitHub Desktop.

Select an option

Save fabiocerqueira/66ece5d16186519299ba326082001fc9 to your computer and use it in GitHub Desktop.
example how map works(python3)
class mymap:
def __init__(self, func, seq):
self.func = func
self.seq = iter(seq)
def __iter__(self):
return self
def __next__(self):
return self.func(next(self.seq))
def mymap2(func, seq):
for e in seq:
yield func(e)
if __name__ == '__main__':
for i in mymap(lambda x: x*2, range(10)):
print(i)
for i in mymap2(lambda x: x*2, range(10)):
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment