Skip to content

Instantly share code, notes, and snippets.

@Alfex4936
Created October 18, 2020 10:11
Show Gist options
  • Save Alfex4936/9d57c3f2e3e14db70db60d5483aa91fa to your computer and use it in GitHub Desktop.
Save Alfex4936/9d57c3f2e3e14db70db60d5483aa91fa to your computer and use it in GitHub Desktop.
Python: fastcore Self usage
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