Skip to content

Instantly share code, notes, and snippets.

@mrtj
Last active April 1, 2025 08:40
Show Gist options
  • Save mrtj/59acbc5c4973da4cd8dd8e7d657d1d6c to your computer and use it in GitHub Desktop.
Save mrtj/59acbc5c4973da4cd8dd8e7d657d1d6c to your computer and use it in GitHub Desktop.
Function pipeline definition in python
from typing import Callable, Any
from functools import reduce, partial
def pipeline(*functions: Callable[[Any], Any]) -> Callable[[Any], Any]:
""" Creates a pipeline from a sequence of functions.
Usage:
processor = pipeline(str.lower, str.split)
processor("Hello World")
# ['hello', 'world']
"""
return partial(reduce, lambda x, f: f(x), functions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment