What Is This?
pfun is a Python library that aims to make functional programming in Python fun and easy. On its own, Python has all the features necessary to write code in functional style. However, many programmers find functional programming in Python difficult and tedious because it lacks features supporting common functional design patterns.
pfun supplies the last few puzzle pieces that make functional programming in Python ergonomical. Specifically:
pfunprovides a simple, unified api for working with any side-effect in functional style through a full-fledged functional effect system that doesn't rely on complex solutions such as monad transformers.
- Python doesn't perform tail call optimization which is a problem for many functional design patterns that rely on recursion.
pfunsolves this by building Cython optimized trampolining into its effect system.
pfunprovides immutable data structures with a functional api, as well as tools for building your own immutable data types.
- The Python type annotations are often too limited to accurately type common functional design patterns.
pfunsolves this by including a MyPy plugin that provides very precise typing.
pfunintegrates functional patterns for async programming with the
pfun differs from other libraries for functional Python programming in that
pfuntakes a modern approach to functional programming inspired by state of the art solutions to working with side-effects from functional programming languages (specifically the Zio Scala libary)
pfunwas designed with a strong emphasis on static type checking
pfunis designed to be "pythonic", using Python conventions and best practices when possible, favouring easy to understand names over functional programming jargon, and integrating with the Python standard library as much as possible.