stdlibx-compose

This package provides simple utilities for composing functions. It includes flow() for applying functions left-to-right to a value, and pipe() for building reusable function pipelines. This makes it easy to structure logic as small, composable steps.

Installation

pip install stdlibx-compose
uv add stdlibx-compose
poetry add stdlibx-compose
pipenv install stdlibx-compose

Examples

Simple

from stdlibx.compose import flow, pipe

# Define simple functions
def double(x: int) -> int:
    return x * 2

def add_ten(x: int) -> int:
    return x + 10

# Compose left-to-right with flow
result = flow(
    5,
    double,
    add_ten,
)
print(result)

Reusable Pipeline

from typing import Callable

from stdlibx.compose import pipe

# Create a reusable pipeline
process_numbers: Callable[[int], float] = pipe(
    lambda x: x * 2,
    lambda x: x + 5,
    lambda x: x / 2,
)

print(process_numbers(10))
print(process_numbers(20))