{"id":16889331,"url":"https://github.com/dcbaker/python-maybe","last_synced_at":"2025-03-20T07:17:36.537Z","repository":{"id":67596214,"uuid":"223289329","full_name":"dcbaker/python-maybe","owner":"dcbaker","description":"A maybe pattern implementation for python","archived":false,"fork":false,"pushed_at":"2019-11-25T18:51:20.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T08:27:41.300Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/dcbaker.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}},"created_at":"2019-11-22T00:16:44.000Z","updated_at":"2019-11-25T18:51:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"16a4589b-6712-468d-b843-a5a02bd9bda3","html_url":"https://github.com/dcbaker/python-maybe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcbaker%2Fpython-maybe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcbaker%2Fpython-maybe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcbaker%2Fpython-maybe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcbaker%2Fpython-maybe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcbaker","download_url":"https://codeload.github.com/dcbaker/python-maybe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244566948,"owners_count":20473451,"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":[],"created_at":"2024-10-13T16:56:49.999Z","updated_at":"2025-03-20T07:17:36.530Z","avatar_url":"https://github.com/dcbaker.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python-maybe\n\npython-maybe is a python3 only maybe implementation.\n\n\n## What is it?\n\nIt implements as close to a maybe pattern as can probably be done in python,\nit is similar to the null object pattern, except that it treats all values\nexcept one special value (`EMPTY`) as valid values. The idea is to simplify\ncases where a value is optional, making code easier to understand but without\nsacrificing correctness.\n\nGiven an arbitrarily deep attribute list one normally ends up with really\nugly None checks:\n\n```python\nclass A:\n\n    def __init__(self, v: typing.Optional[typing.Union[A, B]] = None):\n        self.v = v\n\n\nclass B:\n\n    def __init__(self, a: str):\n        self.a = a\n\n\ndef fun() -\u003e str:\n    f = A(A(A(B('foo'))))\n\n    if f.v and f.v.v and f.v.v.v\n        return f.v.v.v.a\n    return 'Unknown value'\n```\n\nWith the maybe pattern we can simplify that:\n\n```python\ndef fun() -\u003e str:\n    f = Maybe(A(A(A(B('foo')))))\n\n    return f.v.v.v.a.otherwise('Unknown value')\n```\n\n\n## What about pymaybe?\n\nI was inspired by pymaybe, and I've used it a fair bit. There are a couple of\nthings. One is I don't care about python 2, at all. The second is that it\nuses None as it's sentinel value, which means that cases where you actually\nwant None cannot be distinguished from cases where pymaybe has used None to\nrepresent a lack of value.\n\nCases like:\n\n```python\nfrom pymaybe import maybe\n\nmaybe([None])[0].is_none() == True\n```\n\npython-maybe doesn't have this problem, because it uses a unique sentinel value:\n\n```python\nfrom maybe.maybe import Maybe\n\nMaybe([None])[0].is_something() == True\n```\n\nBe aware that python-maybe doesn't have an equivalent to is_none, is only has is_something()\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcbaker%2Fpython-maybe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcbaker%2Fpython-maybe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcbaker%2Fpython-maybe/lists"}