Created
October 18, 2020 10:11
-
-
Save Alfex4936/9d57c3f2e3e14db70db60d5483aa91fa to your computer and use it in GitHub Desktop.
Python: fastcore Self usage
This file contains hidden or 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 fastcore.utils import Self, L | |
if __name__ == "__main__": | |
f = Self.sum() | |
x = L(1, 2, 3) | |
print(f(x)) | |
f = Self.map(lambda a: a + 1) | |
x = L(1, 2, 3) | |
print(f(x)) | |
f = Self.map(float) | |
x = L(1, 2, 3) | |
print(f(x)) | |
f = Self.map(lambda a: a ** 2) | |
x = L(1, 2, 3) | |
print(f(x)) | |
f = Self.filter(lambda a: a % 2 == 1) | |
x = L(1, 2, 3) | |
print(f(x)) | |
f = Self.reduce(lambda a, b: a if a > b else b) | |
x = L(1, 2, 3) | |
print(f(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment