{"id":16371880,"url":"https://github.com/qard/potentially","last_synced_at":"2026-03-13T00:30:19.846Z","repository":{"id":57328955,"uuid":"196397494","full_name":"Qard/potentially","owner":"Qard","description":"A maybe/option type implementation with separate derived types to reduce branching","archived":false,"fork":false,"pushed_at":"2019-07-11T13:17:56.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T08:33:20.074Z","etag":null,"topics":["fp","functional-programming","maybe","monad","nodejs","option"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-11T13:12:58.000Z","updated_at":"2019-07-11T13:27:52.000Z","dependencies_parsed_at":"2022-09-15T01:02:57.721Z","dependency_job_id":null,"html_url":"https://github.com/Qard/potentially","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fpotentially","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fpotentially/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fpotentially/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qard%2Fpotentially/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qard","download_url":"https://codeload.github.com/Qard/potentially/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239914935,"owners_count":19717760,"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":["fp","functional-programming","maybe","monad","nodejs","option"],"created_at":"2024-10-11T03:09:51.107Z","updated_at":"2026-03-13T00:30:19.711Z","avatar_url":"https://github.com/Qard.png","language":"JavaScript","readme":"# potentially\n\nA maybe/option type implementation with separate derived\ntypes to reduce branching.\n\n## Install\n\n```sh\nnpm install potentially\n```\n\n## Usage\n\n```js\nconst { Maybe, None, Some } = require('potentially')\n\nSome.of(1) // Some(1)\n  .and(None.of()) // None\n  .or(Maybe.of(2)) // Some(2)\n  .map(v =\u003e v * 2) // Some(4)\n  .filter(v =\u003e v === 2) // None\n  .expect(\"Oh no! It's a None! :(\") // throws because there is no value\n```\n\n### API\n\n#### `Maybe.of([ value ])`\n\nIf `value` is `undefined` this function will return a `None` instance, otherwise it will return a `Some` instance containing the value. If value is already a `Maybe` it will just return the value. It is recommended to use `None.of(...)` and `Some.of(...)` instead if you already know which type it should be.\n\n#### `Maybe.some(value)`\n\nReturns a `Some` instance containing the value.\n\n#### `Maybe.none()`\n\nReturns a `None` instance.\n\n#### `None.of()`\n\nReturns a `None` instance, ignoring any input value if provided.\n\n#### `Some.of(value)`\n\nReturns a `Some` instance containing the value.\n\n#### `maybe.isSome`\n\n`None`: Returns false.\n`Some`: Returns true.\n\n#### `maybe.isNone`\n\n`None`: Returns true.\n`Some`: Returns false.\n\n#### `maybe.value`\n\n`None`: Throws an error with a `'Maybe is empty'` message.\n`Some`: Returns the contained value.\n\n#### `maybe.expect(message)`\n\n`None`: Throws an error with the given `message`.\n`Some`: Returns the contained value.\n\n#### `maybe.map(func)`\n\n`None`: Returns `this` and skips the `func` as `None` types should remain `None` types.\n`Some`: Returns a `Maybe` of the result of calling `func` with the contained value. Can also return `Maybe` types from `func` to determine type explicitly rather than relying on internal type checking of `Maybe`, this allows a `Some` to contain `undefined`. \n\n#### `maybe.filter(func)`\n\n`None`: Returns `this` and skips the `func` as `None` types should remain `None` types.\n`Some`: Calls `func` on the contained value and return `None` if `false` or `this` if `true`.\n\n#### `maybe.and(other)`\n\n`None`: Returns `this` because it fails the left-hand condition of the `and` check and should remain `None`.\n`Some`: Returns `other` because it passes the left-hand condition.\n\n#### `None.or(other)`\n\n`None`: Returns `other` because it fails the left-hand condition of the `or` check.\n`Some`: Returns `this` because it passes the left-hand condition.\n\n---\n\n### Copyright (c) 2019 Stephen Belanger\n\n#### Licensed under MIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqard%2Fpotentially","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqard%2Fpotentially","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqard%2Fpotentially/lists"}