faif / python-patterns

A collection of design patterns/idioms in Python
40.56k stars 6.94k forks source link

[Question] Functional Programming Patterns #244

Open fkromer opened 6 years ago

fkromer commented 6 years ago

Would you accept PRs about functional programming patterns @faif ? Would probably imply some project restructuring (e.g. putting dirs "behavioral" and "structural" into "oop").

faif commented 6 years ago

I'm a big fan of fp but although you can do it in Python, it is not always considered idiomatic. It's not a bad idea but I'm not sure if it's good to put it in this repo. I'd like to hear some thoughts from the rest of the community.

fkromer commented 6 years ago

(...) although you can do it in Python, it is not always considered idiomatic.

As far as I know/learned until now some functional programming in Python is very pythonic. However these kind of patterns are more idioms than higher level patterns and not really suitable for the repo (due to low level).

gyermolenko commented 5 years ago

+1 for functional patterns here.

@fkromer had you something particular in mind? We should probably make a list to briefly discuss it before actually implementing(or copying).

I'll start proposing "pipeline" candidate

fkromer commented 5 years ago

I had the patterns addressed in S. Lott's "Functional Python Programming" in mind. In case you want to look into the book pay attention before doing so: There is a section about patterns and some references in the index but the majority of examples is spread over the whole book. It makes sense to depend on some Python package(s) which implement boilerplate required to implement the actual patterns. As @faif already said: I am not sure if it's a good idea to put this into here.

Recently I started a small project called 30 seconds of functional python programming. Right now it's a collection of Python package API examples running in an interactive Python environment on Binder. Python packages for functional programming have been hardly addresses in the books I've looked into so far. The packages provide lowest level building blocks to adapt a FP style beyond what you can do with Pythons builtin and standard lib stuff. I think it's way more effective to learn new programming language features via exploratory experimentation. I've not pushed everything I've prepared so far but I will do so that you get a better understanding of what the project is aiming for. E.g. I'd like to port the JavaScript examples from Functional Programming Jargon to Python as well. And it would be reasonable to put pattern examples/implementations into specific Python package specific sections as well. Feel free to contribute there as well.

fkromer commented 5 years ago

I'll start proposing "pipeline" candidate

Another higher level candidate: Parallel Functional Pipeline Pattern

mpkocher commented 4 years ago

Perhaps this repo would be a better place to centralize functional programming pattens and concepts in Python.

https://github.com/sfermigier/awesome-functional-python

SakigamiYang commented 2 years ago

In my opinion, Python is not a good language for FP (many use cases are not covered), although it has some of the ideas of FP. So I think FP Pattern should not be included in this repository because this feature is not complete.

[From this page: https://intellipaat.com/community/12542/why-isnt-python-very-good-for-functional-programming] Below is a list of some functional things which you will miss in Python:

ESE-Wahaj commented 1 year ago

A project accepts PRs on functional programming patterns would depend on the project's goals and the maintainers' preferences. If the project's focus is on object-oriented programming, the maintainers may not be interested in adding functional programming patterns or restructuring the project in that way. However, if the maintainers are open to adding functional programming patterns, restructuring the project may make sense, and PRs related to functional programming could be considered. Ultimately, the best course of action would be to reach out to the maintainers and ask for their thoughts on the matter.

faif commented 1 year ago

I believe that functional programming idioms in any language are good, as long as they are not implemented in an obscure way. Especially the fundamentals such as immutability and pure functions can be very beneficial to Python programmers. So if people are willing to showcase them here, maybe it's a good idea to include them.