r/functionalprogramming • u/redd-sm • Jun 29 '21
Python good examples of functional-like python code that one can study?
Would love to be able to study some real world python code that is written in functional style. Have not come across any. They must exist out there given the interest in functional and interest in python.
Thank you for sharing.
16
Upvotes
View all comments
Show parent comment
3
u/kluvin Jun 30 '21 edited Jun 30 '21
I ended up reading SICP (scheme), but only got to chapter two so far, as I also started picking up OCaml. In my day-to-day I use ES6, and indeed JS is a practical language to write FP in.
If I had the option, I would depend on an FP tool set, and there are many in the JS ecosystem:
Sanctuary seems the most attractive to me, Ramda works very well too, and is fairly common. As I could tell, lodash-fp isn't that great. ReScript is also a great choice. That's JS-based syntax backed by the OCaml typechecker, so it is a much more solid typed JS than TypeScript.
What you definitely want is some form of pipes and partially applied functions. Pattern matching is also very nice. Learning a new language that supports these mechanisms as a first-class citizen has had a great effect in how I structure my programs in JS, where I don't have them.
From your goals, I wouldn't recommend OCaml for starters. It's a great language and so is the community, but it is hard to learn.
Self-plugging a bit more. I am still trying to push FP code into Python, and so I'm working on implementing Wish solitaire in both Python and OCaml. Though the OCaml implementation I am not totally sure is working correctly yet.
https://gitlab.com/kluvin/wish-solitaire