{"id":30810348,"url":"https://github.com/izzet/betterset","last_synced_at":"2026-01-29T04:13:39.415Z","repository":{"id":312495310,"uuid":"1047695224","full_name":"izzet/betterset","owner":"izzet","description":"Extended set operations: algebraic, functional, and utilities on top of Python set","archived":false,"fork":false,"pushed_at":"2025-08-31T03:20:27.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-15T11:40:57.409Z","etag":null,"topics":["algebra","cartesian","functional","powerset","python","set"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/betterset/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izzet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-31T02:22:56.000Z","updated_at":"2025-08-31T22:47:53.000Z","dependencies_parsed_at":"2025-08-31T03:40:05.329Z","dependency_job_id":"afacad86-c2db-46b3-9a01-f89cc0347dc9","html_url":"https://github.com/izzet/betterset","commit_stats":null,"previous_names":["izzet/betterset"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/izzet/betterset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzet%2Fbetterset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzet%2Fbetterset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzet%2Fbetterset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzet%2Fbetterset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izzet","download_url":"https://codeload.github.com/izzet/betterset/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izzet%2Fbetterset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28862142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"online","status_checked_at":"2026-01-29T02:00:06.714Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algebra","cartesian","functional","powerset","python","set"],"created_at":"2025-09-06T05:10:37.450Z","updated_at":"2026-01-29T04:13:39.407Z","avatar_url":"https://github.com/izzet.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# betterset\n\n[![PyPI version](https://badge.fury.io/py/betterset.svg)](https://badge.fury.io/py/betterset)\n[![GitHub release](https://img.shields.io/github/v/release/izzet/betterset)](https://github.com/izzet/betterset/releases)\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n\nExtended set operations: algebraic, functional, and utilities on top of Python's built-in `set`.\n\n## Features\n\n- **Operator overloads**: `+` union, `*` cartesian product, `**` n-fold cartesian, `@` relation composition\n- **Algebraic utilities**: `powerset`, `cartesian`, `complement`, `disjoint`, `partition`, `closure`\n- **Functional utilities**: `map`, `filter`, `reduce`, and `flatten`\n- **Drop-in feel**: Built directly on top of `set`\n\n## Installation\n\n```bash\npip install betterset\n```\n\nOr with uv:\n\n```bash\nuv add betterset\n```\n\n## Quick Start\n\n```python\nfrom betterset import BetterSet as S\n\nA = S({1, 2, 3})\nB = S({3, 4})\n\n# Operators\nassert (A + B) == {1, 2, 3, 4}          # union via +\nassert (A * {\"x\", \"y\"}) == {(1, \"x\"), (1, \"y\"), (2, \"x\"), (2, \"y\"), (3, \"x\"), (3, \"y\")}\nassert (S({1, 2}) ** 2) == {(1, 1), (1, 2), (2, 1), (2, 2)}\nassert (S({(1, 2), (2, 3)}) @ S({(2, 5), (3, 7)})) == {(1, 5), (2, 7)}\n\n# Algebraic\nps = A.powerset()                        # set of frozensets\nassert frozenset({1, 2}) in ps\nassert A.disjoint({4, 5}) is True\nassert A.complement({1, 2, 3, 4, 5}) == {4, 5}\nparts = A.partition(2)                   # partitions into 2 non-empty blocks\n\n# Functional\nassert A.map(lambda x: x % 2) == {0, 1}\nassert A.filter(lambda x: x \u003e= 2) == {2, 3}\nassert A.reduce(lambda acc, x: acc + x, 0) == 6\nassert S.flatten([[1, 2], {2, 3}, (3, 4)]) == {1, 2, 3, 4}\n\n# Cartesian as method\nassert A.cartesian({\"x\"}) == {(1, \"x\"), (2, \"x\"), (3, \"x\")}\n\n# Closure under an operation\ndef step(x: int):\n    return [x + 1] if x \u003c 3 else []\n\nassert S({1}).closure(step) == {1, 2, 3}\n```\n\n## API Reference\n\n### Class: `BetterSet`\n\n- Operators\n\n  - `A + B` → union\n  - `A * B` → cartesian product of elements as tuples\n  - `A ** n` → n-fold cartesian product (`A ** 0 == {()}`)\n  - `A @ B` → relation composition when `A` and `B` are sets of pairs\n  - In-place variants: `+=`, `*=`\n\n- Algebraic methods\n\n  - `powerset() -\u003e BetterSet[FrozenSet[T]]`\n  - `cartesian(other: Iterable[U]) -\u003e BetterSet[tuple[T, U]]`\n  - `disjoint(other: Iterable[T]) -\u003e bool`\n  - `complement(universe: Iterable[T]) -\u003e BetterSet[T]`\n  - `partition(k: int) -\u003e BetterSet[tuple[tuple[T, ...], ...]]`\n  - `closure(op: Callable[[T], Iterable[T]]) -\u003e BetterSet[T]`\n\n- Functional methods\n  - `map(func: Callable[[T], U]) -\u003e BetterSet[U]`\n  - `filter(predicate: Callable[[T], bool]) -\u003e BetterSet[T]`\n  - `reduce(func: Callable[[U, T], U], initial: Optional[U] = None) -\u003e U`\n  - `@classmethod flatten(iterable: Iterable[Union[Iterable[T], T, None]], *, skip_none: bool = True) -\u003e BetterSet[T]`\n\nNotes on `flatten`:\n- Strings/bytes/bytearray/memoryview are treated as atomic values.\n- Other iterables are flattened (e.g., frozenset, numpy arrays).\n- Mappings iterate keys by default; use `mapping.items()` for key/value pairs.\n- `None` values are skipped by default (`skip_none=True`).\n\n## Requirements\n\n- Python 3.8+\n\n## Development\n\n```bash\n# Clone the repository\ngit clone https://github.com/izzet/betterset.git\ncd betterset\n\n# Install with uv (uses uv.lock for reproducible builds)\nuv sync --group dev\n\n# Set up pre-commit hooks (recommended)\nuv run pre-commit install\n\n# Run tests\nuv run pytest\n\n# Format code\nuv run ruff format .\n\n# Check linting\nuv run ruff check .\n\n# Build package\nuv build\n```\n\n**Note**: This project uses `uv.lock` for reproducible dependency management. The lock file is committed to ensure all developers and CI/CD use identical dependency versions.\n\n**Pre-commit hooks**: The project includes pre-commit hooks that automatically format code, check linting, and run tests before each commit to maintain code quality.\n\n## License\n\nMIT License. See [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzet%2Fbetterset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizzet%2Fbetterset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizzet%2Fbetterset/lists"}