Last active
April 1, 2025 08:40
-
-
Save mrtj/59acbc5c4973da4cd8dd8e7d657d1d6c to your computer and use it in GitHub Desktop.
Function pipeline definition in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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