
Trying to Understand Functional Programming with State in Python - crul
I&#x27;m trying to understand how to use functional programming with python. AFAIK this is a way to handle state with immutable data.<p>https:&#x2F;&#x2F;pyfiddle.io&#x2F;fiddle&#x2F;db7f130e-e2bd-4d13-ac4e-0114c09a6179<p>The example is a service that keeps the total of the random values generated. It&#x27;s only a dummy program with state management for learning purposes.<p>The generator simulates (that was my intention) a data stream from a remote server via (e.g.) a websocket. I want to mantain a local state and update it with the received events.<p>I have some questions:<p>- Is this a good functional approach for python?<p>- Is there a way to remove the while True in the main function? I think it can be done with recursion, but I read python doesn&#x27;t have tail call and it&#x27;s bad idea.<p>- Is it possible to refactor with the map (or similar) function?<p>- Is there any library suited for this example? I looked at PyFunctional and RxPy, but I&#x27;m not sure.<p>I&#x27;m afraid these are not the right questions, so feel free to suggest any correction, improvement or resource to look at. Thanks.
======
crul
Clickable link
[https://pyfiddle.io/fiddle/db7f130e-e2bd-4d13-ac4e-0114c09a6...](https://pyfiddle.io/fiddle/db7f130e-e2bd-4d13-ac4e-0114c09a6179)

