{"id":19999856,"url":"https://github.com/eliphatfs/2us","last_synced_at":"2025-11-25T17:02:42.287Z","repository":{"id":57407639,"uuid":"308547614","full_name":"eliphatfs/2us","owner":"eliphatfs","description":"Glueing functionals by `import __` for python!","archived":false,"fork":false,"pushed_at":"2020-10-30T09:50:28.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T20:16:06.437Z","etag":null,"topics":["functional-programming","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliphatfs.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}},"created_at":"2020-10-30T06:46:57.000Z","updated_at":"2020-11-11T05:26:36.000Z","dependencies_parsed_at":"2022-09-26T17:10:20.264Z","dependency_job_id":null,"html_url":"https://github.com/eliphatfs/2us","commit_stats":null,"previous_names":["strongrex2001/2us"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2F2us","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2F2us/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2F2us/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliphatfs%2F2us/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliphatfs","download_url":"https://codeload.github.com/eliphatfs/2us/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241439484,"owners_count":19963095,"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":["functional-programming","python"],"created_at":"2024-11-13T05:13:08.738Z","updated_at":"2025-11-25T17:02:37.257Z","avatar_url":"https://github.com/eliphatfs.png","language":"Python","readme":"# __ (Double Underscores, 2us)\n[![PyPI version](https://badge.fury.io/py/2us.svg)](https://badge.fury.io/py/2us)\n\nGlueing functionals by `import __` for python!\n\n## Install\nThe package is written in pure python, with no dependencies other than the Python language. Just do:\n\n```sh\npip install 2us\n```\n\nRequires Python 3.5 or higher.\n\n## Why this?\nPython is a great language for creating convenient wrappers around native code and implementing simple, human-friendly functions.\nIn python, a bunch of builtin higher-order methods (which means that they accept functions as arguments) such as `map`, `filter` are available.\nThey enable streamed data processing on containers that focus on the processing itself,\nin contrast with *noisy code* on traditional command-based languages that is heavily involved in loops.\n\nHowever, you may occasionally run into the situation where you find that there is no standard library functions to implement in-line unpacking of tuples,\nadding all numbers in a list by a constant shift, so you will have to write:\n```python\nmap(lambda x: x + 1, some_list)\nmap(lambda x: x[0], some_list)\n```\nwhich seems rather dumb due to the inconvenient definition of lambda functions in python.\n\n## Using __\nStart using the package by importing `__`:\n```python\nimport __\n```\nAnd then `__` can be used to create convenient functions that are identical to those written with `lambda`. Examples:\n```python\nassert sum(map(__ + 1, range(1000))) == sum(map(lambda x: x + 1, range(1000)))\nassert set(map(__[0], {1: 2, 4: 6}.items())) == {1, 4}\nassert functools.reduce(__ + __, range(1000)) == sum(range(1000))\n```\nCurrently there is a drawback: python do not support overriding `__contains__` returning non-boolean values, so the `in` condition should be handled separately.\n```python\nassert tuple(map(__.is_in([1, 2]), [3, 1, 5, 0, 2])) == (False, True, False, False, True)\nassert list(map(__.contains('1'), '13')) == [True, False]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliphatfs%2F2us","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliphatfs%2F2us","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliphatfs%2F2us/lists"}