{"id":21767030,"url":"https://github.com/sigmasoldi3r/ts-option","last_synced_at":"2026-04-29T10:06:17.464Z","repository":{"id":44787578,"uuid":"451450279","full_name":"sigmasoldi3r/ts-option","owner":"sigmasoldi3r","description":"Optional values for typescript","archived":false,"fork":false,"pushed_at":"2023-06-26T06:51:09.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-17T04:31:19.879Z","etag":null,"topics":["functional-programming","iterables","optional","optional-chaining"],"latest_commit_sha":null,"homepage":"https://sigmasoldi3r.github.io/ts-option/","language":"TypeScript","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/sigmasoldi3r.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}},"created_at":"2022-01-24T12:12:45.000Z","updated_at":"2023-06-26T06:52:53.000Z","dependencies_parsed_at":"2025-06-12T04:08:12.012Z","dependency_job_id":"75d34893-c211-4a7a-8f4a-85accef8dfe4","html_url":"https://github.com/sigmasoldi3r/ts-option","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sigmasoldi3r/ts-option","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigmasoldi3r%2Fts-option","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigmasoldi3r%2Fts-option/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigmasoldi3r%2Fts-option/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigmasoldi3r%2Fts-option/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigmasoldi3r","download_url":"https://codeload.github.com/sigmasoldi3r/ts-option/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigmasoldi3r%2Fts-option/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32420403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["functional-programming","iterables","optional","optional-chaining"],"created_at":"2024-11-26T13:21:38.270Z","updated_at":"2026-04-29T10:06:17.435Z","avatar_url":"https://github.com/sigmasoldi3r.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Option ![Typescript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge\u0026logo=typescript\u0026logoColor=white)\n\n![License](https://img.shields.io/github/license/sigmasoldi3r/ts-option.svg)\n\nOptional values are meant to describe a value that is\n_explicitly_ present or not.\n\nThis makes the presence of the value more clear, in contrast\nto making the value nullable (Which will not work if the\ncompiler is not set to check strictly null values), or\nundefined.\n\nAs a side effect, makes an optional value capable of holding\na null value, because you might encounter situations where\nyou want a null value to be a valid one.\n\n## Installation\n\nRun `yarn add @octantis/option` or `npm i @octantis/option`\n\n## API\n\nOption is iterable, in case that the value is present yields\nthe value.\n\nThe option value is meant to mimic Scala's `option[A]` type.\n\n```ts\n/**\n * True if not empty\n */\nisDefined(): this is Some\u003cA\u003e;\n/**\n * Return value, throw exception if empty\n */\nget(): A;\n/**\n * True if empty\n */\nisEmpty(): this is None\u003cA\u003e;\n/**\n * True if not empty\n */\nnonEmpty(): this is Some\u003cA\u003e;\n/**\n * Evaluate and return alternate optional value if empty\n */\norElse(alternative: option\u003cA\u003e): option\u003cA\u003e;\n/**\n * Evaluate and return alternate value if empty\n */\ngetOrElse(alternative: A): A;\n/**\n * Apply function on optional value, return default if empty\n */\nfold\u003cB\u003e(fallback: B, folder: (value: A) =\u003e B): B;\n/**\n * Apply a function on the optional value\n */\nmap\u003cB\u003e(map: (value: A) =\u003e B): option\u003cB\u003e;\n/**\n * Same as map but function must return an optional value\n */\nflatMap\u003cB\u003e(map: (value: A) =\u003e option\u003cB\u003e): option\u003cB\u003e;\n/**\n * Apply a procedure on option value\n */\nforEach(consumer: (value: A) =\u003e void): void;\n/**\n * Apply partial pattern match on optional value\n */\ncollect\u003cB\u003e(collector: (value: A) =\u003e B | undefined): option\u003cB\u003e;\n/**\n * An optional value satisfies predicate\n */\nfilter(filter: (value: A) =\u003e boolean): option\u003cA\u003e;\n/**\n * An optional value doesn't satisfy predicate\n */\nfilterNot(filter: (value: A) =\u003e boolean): option\u003cA\u003e;\n/**\n * Apply predicate on optional value, or false if empty\n */\nexists(predicate: (value: A) =\u003e boolean): boolean;\n/**\n * Apply predicate on optional value, or true if empty\n */\nforAll(predicate: (value: A) =\u003e boolean): boolean;\n/**\n * Checks if value equals optional value, or false if empty\n */\ncontains\u003cB extends A\u003e(element: B): boolean;\n/**\n * Combine two optional values to make a paired optional value\n */\nzip\u003cB\u003e(that: option\u003cB\u003e): option\u003c[A, B]\u003e;\n/**\n * Unary list of optional value, otherwise the empty list\n */\ntoList(): A[];\n```\n\n## Example usage\n\nSimplest example:\n\n```ts\n// Assume a function\nfunction maybe(): option\u003cnumber\u003e\n\nlet n = maybe()\n\n// This acts as a guard, so now n is of type Some\u003cnumber\u003e\nif (n.isDefined()) {\n  console.log(`n = ${n.value}`)\n}\n\n// Or at runtime\nconsole.log(`n = ${n.get()}`)\n// This throws if the value wasn't present.\n```\n\nWith iteration:\n\n```ts\nfor (const value of maybe()) {\n  console.log(`value = ${value}`)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigmasoldi3r%2Fts-option","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigmasoldi3r%2Fts-option","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigmasoldi3r%2Fts-option/lists"}