Skip to main content

Functional Programming Library and Lessons

Project description


date: 2025-11-06 tags: [functional programming, python, library] author: George Cummings

Functional Programming Support

This project has three goals:

  • Provide functional programming helpers up and beyond official Python functional programming tools
  • Assist in teaching junior Python programmers functional programming
  • Provide a pathway for Python programmers to more easily learn compiled, typed languages.

Do not get me wrong: I enjoy programming in Python. Its readability, libraries, and quick development cycle is second to none. It is not tied to any programming style, be it imperative, procedural, object-oriented, or functional. I am not blind, however, to programming missteps and debugging chaos. These obstacles can be prevented by type checking and using easy-to-test, "pure" functions.

There are, of course, many many quality Python projects creating functional tools. I encourage developers to explore them as well and see if they suit their needs.

Licence

The code and documentation is licensed under the Apache 2.0 licence. See LICENCE.

Installation

pip install fpsupport

TL;DR

This is an example of using monads to hide IO functions.

from fpsupport.jinja import load_template, render
from fpsupport.monad import Monad
from fpsupport.struct import IOType

def render_from_file(io: Monad, template_filepath: str, data: dict) -> str | None:
    """Generate a message from a jinja2 template.
    
    Any I/O Exceptions will have stopped processing and returned the error message.
    """
    result = unwrap(io.join(load_template, template_filepath).join(render, data))
    return result.contents if result.ok else result.error_msg

print(render_from_file(
    Monad(IOType()),
    "greeting.txt.j2",
    {"holiday": "Birthday", "to": "Mum", "from": "Gus"}
))

To see how render_from_file is unit tested and how IO is dealt with without mocking, read the example.

Training Materials

Functional programming (FP) holds the promise of correct, easy to follow, and easily maintained software. Object-oriented programming (OOP) also holds that promise. Acceptance-driven, behaviour-driven and test- driven development along with integration testing hold programmers to a higher quality.

All of these concepts can be difficult to comprehend without experience. My notes and other materials are posted here as well along with their references. My intention is to provide exercises as well.

Training materials will be published as I become more proficient at both functional programming in Python and in documentation. In the meantime, I recommend you watch Boot Dev's Functional Programming Full Course.

Development and Use of this Library

The library is published in PyPi. I am using Agile principles, even as a one-man project. This means that the software will be minimal to begin with, but guaranteed to work. As the project continues, so grows its worth. The speed of development depends on my professional and family work-load.

Statement on the Use of AI

See my Personal Policy on the Use of Artificial Intelligence.

Project layout

mkdocs.yml    # The configuration file.
docs/
    index.md  # The documentation homepage.
    ...       # Other markdown pages, images and other files.
examples/     # How to use the library
fpsupport/    # The library. As it expands, so will the folders
test/         # Unit testing. Functional and integration testing are not applicable.

Examples

Monads

This library includes monadic patterns such as State, Maybe and Writer monads. In the case of the monad that I call Pipeline, it incorporates all three to be used as a logged chain-of-responsibility1 pattern.

Of interest to a TDD2 enthusiast is the use of the monad for IO, used to hide not only system calls but any other side effect or non-deterministic3 value that plays havoc with the proof of a function. It is used in dependency injection4, so there would be no need to use monkeypatching in unit tests.

Why start with Monads?

Oh my stars, you say. Monads ... are you kidding me?

When it comes to functional programming, Monads are considered advanced by most of the online courses I remember. There are many, many tutorials on Monads on YouTube. Their quality varies. Some lectures on them are pure Category Theory, which can be depressing to the programmer in a rush. Others are pedantic, pushing ideology over need. Most ignore Python.

Monads are hard to explain but are so very, very useful. I am starting with Monads because I have already used them to great visible effect on a critical, team-based project at work. I write visible because Python decorators -- effectively the definition of a higher-order function -- are so ubiquitous as to be unnoticed.

Are monads Pythonic?

See The Zen of Python.

This will be debated in the training materials once written. The answer is, quite frankly, up to the writer. They certainly seem to add complication at first glance, violating simple is better than complex. However, it enforces explicit is better than implicit and, properly used, is the epitome of readability counts.

Development

make setup

Now you can program away without messing up my standards. For suggested VS Code plugins, see preferences.

  1. Refactoring.Guru. Chain of Responsibility, retrieved Nov 26, 2025.

  2. Test-driven development, used to encourage technical correctness. It works alongside BDD (Behaviour-Driven Development for system behaviour), and ATDD (Acceptance Test-Driven Development as an Agile collaboration with stakeholders).

  3. For example, a random number generator.

  4. That is to say, converting a system call made from inside a function to an argument of that function.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fpsupport-0.1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fpsupport-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file fpsupport-0.1.0.tar.gz.

File metadata

  • Download URL: fpsupport-0.1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.9 Linux/6.12.59

File hashes

Hashes for fpsupport-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b4d8ad2e47d476e7177b14033f733b1d205002ce982534b43c38b5c8f143edcf
MD5 00ca2cc0cc374621619ec7216e8c5d40
BLAKE2b-256 963a54b7b166eebffbbf7b58a5ba28d1d10faf35f851b78bd984d9e8498a4d96

See more details on using hashes here.

File details

Details for the file fpsupport-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fpsupport-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.9 Linux/6.12.59

File hashes

Hashes for fpsupport-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d72788ae03b52f2e7685ec675255e43cbd6dd9749e15d50e050a099829b0d958
MD5 dc2a640081719c3abe14b637063640da
BLAKE2b-256 6b4659b4fdddefc94a58d6fa58e74cfaa9c3c33ba32494d82c4aefcb51616480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page