{"id":18263060,"url":"https://github.com/dry-python/lambdas","last_synced_at":"2025-04-05T06:04:23.893Z","repository":{"id":40418289,"uuid":"216362017","full_name":"dry-python/lambdas","owner":"dry-python","description":"Write short and fully-typed lambdas where you need them.","archived":false,"fork":false,"pushed_at":"2023-12-11T18:03:10.000Z","size":648,"stargazers_count":266,"open_issues_count":15,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T20:18:10.622Z","etag":null,"topics":["composition","dry-python","fp","functional-programming","lambda","lambdas","mypy","mypy-plugins","mypy-stubs","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dry-python.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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},"funding":{"github":"dry-python","open_collective":"dry-python"}},"created_at":"2019-10-20T12:57:31.000Z","updated_at":"2024-10-17T21:08:12.000Z","dependencies_parsed_at":"2023-02-17T08:35:32.288Z","dependency_job_id":"4b29830b-5ca1-42ad-bd9f-7f2caceab7e9","html_url":"https://github.com/dry-python/lambdas","commit_stats":{"total_commits":97,"total_committers":5,"mean_commits":19.4,"dds":"0.38144329896907214","last_synced_commit":"eb89d3704eec9c0683b2e058ebadc9bc28feb055"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Flambdas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Flambdas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Flambdas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dry-python%2Flambdas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dry-python","download_url":"https://codeload.github.com/dry-python/lambdas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294529,"owners_count":20915340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["composition","dry-python","fp","functional-programming","lambda","lambdas","mypy","mypy-plugins","mypy-stubs","python","python3"],"created_at":"2024-11-05T11:09:45.969Z","updated_at":"2025-04-05T06:04:23.873Z","avatar_url":"https://github.com/dry-python.png","language":"Python","readme":"[![lambdas logo](https://raw.githubusercontent.com/dry-python/brand/master/logo/lambdas.png)](https://github.com/dry-python/lambdas)\n\n-----\n\n[![Build Status](https://github.com/dry-python/lambdas/workflows/test/badge.svg?branch=master\u0026event=push)](https://github.com/dry-python/lambdas/actions?query=workflow%3Atest)\n[![codecov](https://codecov.io/gh/dry-python/lambdas/branch/master/graph/badge.svg)](https://codecov.io/gh/dry-python/lambdas)\n[![Documentation Status](https://readthedocs.org/projects/lambdas/badge/?version=latest)](https://lambdas.readthedocs.io/en/latest/?badge=latest)\n[![Python Version](https://img.shields.io/pypi/pyversions/lambdas.svg)](https://pypi.org/project/lambdas/)\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)\n[![Telegram chat](https://img.shields.io/badge/chat-join-blue?logo=telegram)](https://t.me/drypython)\n\n-----\n\nWrite short and fully-typed `lambda`s where you need them.\n\n\n## Features\n\n- Allows to write `lambda`s as `_`\n- Fully typed with annotations and checked with `mypy`, [PEP561 compatible](https://www.python.org/dev/peps/pep-0561/)\n- Has a bunch of helpers for better composition\n- Easy to start: has lots of docs, tests, and tutorials\n\n\n## Installation\n\n```bash\npip install lambdas\n```\n\nYou also need to configure `mypy` correctly and install our plugin:\n\n```ini\n# In setup.cfg or mypy.ini:\n[mypy]\nplugins =\n  lambdas.contrib.mypy.lambdas_plugin\n```\n\nWe recommend to use the same `mypy` settings [we use](https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/mypy.toml).\n\n\n## Examples\n\nImagine that you need to sort an array of dictionaries like so:\n\n```python\n\u003e\u003e\u003e scores = [\n...     {'name': 'Nikita', 'score': 2},\n...     {'name': 'Oleg', 'score': 1},\n...     {'name': 'Pavel', 'score': 4},\n... ]\n\n\u003e\u003e\u003e print(sorted(scores, key=lambda item: item['score']))\n[{'name': 'Oleg', 'score': 1}, {'name': 'Nikita', 'score': 2}, {'name': 'Pavel', 'score': 4}]\n```\n\nAnd it works perfectly fine.\nExcept, that you have to do a lot of typing for such a simple operation.\n\nThat's where `lambdas` helper steps in:\n\n```python\n\u003e\u003e\u003e from lambdas import _\n\n\u003e\u003e\u003e scores = [\n...     {'name': 'Nikita', 'score': 2},\n...     {'name': 'Oleg', 'score': 1},\n...     {'name': 'Pavel', 'score': 4},\n... ]\n\n\u003e\u003e\u003e print(sorted(scores, key=_['score']))\n[{'name': 'Oleg', 'score': 1}, {'name': 'Nikita', 'score': 2}, {'name': 'Pavel', 'score': 4}]\n```\n\nIt might really save you a lot of effort,\nwhen you use a lot of `lambda` functions.\nLike when using [`returns`](https://github.com/dry-python/returns) library.\n\nWe can easily create math expressions:\n\n```python\n\u003e\u003e\u003e from lambdas import _\n\n\u003e\u003e\u003e math_expression = _ * 2 + 1\n\u003e\u003e\u003e print(math_expression(10))\n21\n\u003e\u003e\u003e complex_math_expression = 50 / (_ ** 2) * 2\n\u003e\u003e\u003e print(complex_math_expression(5))\n100.0\n```\n\nWork in progress:\n\n- `_.method()` is not supported yet for the same reason\n- `TypedDict`s are not tested with `__getitem__`\n- `__getitem__` does not work with list and tuples (collections), only dicts (mappings)\n\nFor now you will have to use regular `lamdba`s in these cases.\n","funding_links":["https://github.com/sponsors/dry-python","https://opencollective.com/dry-python"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdry-python%2Flambdas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdry-python%2Flambdas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdry-python%2Flambdas/lists"}