Last active
October 27, 2017 00:33
-
-
Save piroyoung/97a713f487ef308587789acc5db8b388 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
from typing import List, Callable, TypeVar | |
from functools import reduce, lru_cache | |
T = TypeVar('T') | |
class MyCollection(List[T]): | |
def reduce(self, f: Callable[[T, T], T]): | |
return reduce(f, self) | |
# example usage | |
obj = MyCollection(range(5)) | |
obj.reduce(lambda x, y: x + y) | |
# example usage | |
obj = MyCollection('hello') | |
obj.reduce(lambda x, y: x + '-' + y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment