Created
December 18, 2017 03:35
-
-
Save dunossauro/9f68663b01c22fc3a3a328b26ca2da01 to your computer and use it in GitHub Desktop.
Rapidinha #3 - programação declarativa com python
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
from collections.abc import MutableSequence | |
from itertools import islice | |
from functools import reduce | |
class List(MutableSequence): | |
def __init__(self, seq): | |
self._d = list(seq) | |
def __delitem__(self, pos): | |
del self._d[pos] | |
def __getitem__(self, pos): | |
return self._d[pos] | |
def __setitem__(self, pos, val): | |
self._d[pos] = val | |
def __len__(self): | |
return len(self._d) | |
def insert(self, pos, val): | |
self._d.insert(pos, val) | |
def __repr__(self): | |
return 'List({})'.format(self._d) | |
def map(self, function): | |
return List(map(function, self._d)) | |
def filter(self, function): | |
return List(filter(function, self._d)) | |
def reduce(self, function): | |
return reduce(function, self._d) | |
def take(self, n): | |
return List(islice(self._d, n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment