Skip to content

wyatt-avilla/py-combinator

Repository files navigation

Py Combinator

Rust Edition Python Version from PEP 621 TOML PyPI - Version PyPI - Wheel MyPy Clippy Nix Flake Check

py-combinator is a high-performance Python library implemented in Rust that provides statically typed iterator combinators for chainable functional operations on iterables.

Example

The following function takes an iterator it and returns a new iterator that produces the squares of the first 10 elements at even indexes from it, in reverse order.

def fn(it: SizedDoubleEndedIterator[int]) -> SizedDoubleEndedIterator[int]:
        return (it
                .enumerate()
                .filter(lambda p: p[0] % 2 == 0)
                .map(lambda p: p[1] ** 2)
                .take(10)
                .rev())

In native Python, it would look like this:

def fn(it: Iterable[int]) -> Iterable[int]:
    return reversed(
        list(
            islice(
                map(
                    lambda p: p[1] ** 2,
                    filter(lambda p: p[0] % 2 == 0, enumerate(it)),
                ),
                10,
            )
        )
    )

Installation

Via Python Package Vendors

uv (and pip)

uv pip install py-combinator

Poetry

poetry add py-combinator

Via Nix Flakes

{
  description = "Minimal example using py-combinator";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/release-25.05";
    py-combinator.url = "github:wyatt-avilla/py-combinator";
  };
  outputs = { nixpkgs, py-combinator, ... }:
    let
      system = "x86_64-linux";  # or your target system
      pkgs = import nixpkgs { inherit system; };
    in {
      packages.${system}.default = pkgs.python312.withPackages (ps: [
        py-combinator.packages.${system}.default
      ]);
    };
}

Similar Libraries

About

Python library with Rust bindings for statically typed iterator combinators

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published