py-combinator is a high-performance Python library implemented in Rust that provides statically typed iterator combinators for chainable functional operations on iterables.
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,
)
)
)
uv pip install py-combinator
poetry add py-combinator
{
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
]);
};
}