Last active
June 14, 2021 09:01
-
-
Save erezsh/c516bba2c0bd9d5a00ef33a5e98d8a13 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 casts import def_cast, cast | |
# Define cast from tuple to list | |
@def_cast(auto=True) | |
def cast_to(i: tuple, cls: list): | |
return cls(i) | |
... | |
class SortedList(list): | |
pass | |
# Define cast from list to SortedList | |
@def_cast(auto=True) | |
def cast_to(l: list, cls: SortedList): | |
return cls(sorted(l)) | |
# Cast tuple->list->SortedList | |
print(cast((4,2), SortedList)) # Prints [2, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment