r/Python • u/Capable-Mall-2067 • May 30 '25
Resource Functional programming concepts that actually work in Python
Been incorporating more functional programming ideas into my Python/R workflow lately - immutability, composition, higher-order functions. Makes debugging way easier when data doesn't change unexpectedly.
Wrote about some practical FP concepts that work well even in non-functional languages: https://borkar.substack.com/p/why-care-about-functional-programming?r=2qg9ny&utm_medium=reddit
Anyone else finding FP useful for data work?
137
Upvotes
View all comments
Show parent comment
1
u/firectlog May 31 '25 edited May 31 '25
You can return whatever you want from this function (well, usually from a decorator above this function) regardless of what
fandgactually mean, you can even make a wrapper that will run similar code in a CUDA kernel and then return the result to the caller, which is one of reasons people bother to deal with AST modification in the first place. Outside of linters/formatting, it's pretty much just numba/cuda stuff. If you feel nice to users of your library, you can throw an exception when the functions you got attempt to do stuff outside of the subset of Python syntax you approve.Doing that is stretching of the definition what CPython is but as long as your users understand what it does...