{"id":18041644,"url":"https://github.com/katyo/stardust-types","last_synced_at":"2026-05-16T18:04:31.517Z","repository":{"id":66335251,"uuid":"112594395","full_name":"katyo/stardust-types","owner":"katyo","description":"Rust-style monadic types implementation for TypeScript","archived":false,"fork":false,"pushed_at":"2018-01-20T16:40:40.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T02:27:44.889Z","etag":null,"topics":["async","either","future","monads","option","result","rust","stream","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/katyo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-30T09:49:40.000Z","updated_at":"2017-11-30T09:51:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"4183969e-95d4-419e-8e93-39dc32e972f4","html_url":"https://github.com/katyo/stardust-types","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/katyo/stardust-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katyo%2Fstardust-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katyo%2Fstardust-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katyo%2Fstardust-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katyo%2Fstardust-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katyo","download_url":"https://codeload.github.com/katyo/stardust-types/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katyo%2Fstardust-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274935947,"owners_count":25376832,"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","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["async","either","future","monads","option","result","rust","stream","typescript"],"created_at":"2024-10-30T16:11:12.895Z","updated_at":"2026-05-16T18:04:31.491Z","avatar_url":"https://github.com/katyo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust-style monad types for TypeScript [![Build Status](https://travis-ci.org/katyo/stardust-types.svg?branch=master)](https://travis-ci.org/katyo/stardust-types)\n\n## Implemented types\n\n### Option\\\u003cItem\u003e\n\nThe option can hold some value or none. This type is preferred to use instead of special values like `null` or `undefined`.\n\n```typescript\nimport { Option, Some, None } from 'stardust-types/option';\n\nfunction square_odd(opt: Option\u003cnumber\u003e): Option\u003cstring\u003e {\n    return opt\n        .and_then(a =\u003e a % 2 ? Some([a, a * a]) : None())\n        .map(([a, s] =\u003e `The square of odd number ${a} is ${s}`)\n        .unwrap_or(\"Please give me odd numbers\");\n}\n\nconsole.log(square_odd(None)); // Please give me odd numbers\nconsole.log(square_odd(Some(1))); // The square of odd number 1 is 1\nconsole.log(square_odd(Some(2))); // Please give me odd numbers\nconsole.log(square_odd(Some(3))); // The square of odd number 3 is 9\n```\n\nSee also: [test/option.ts](test/option.ts)\n\n### Result\u003cItem, Error\u003e\n\nThe result can hold resulting value or error. This type helpful to return from functions or asynchronous operations which may be failed. This type is preferred than throwing errors or using nullable error-result arguments in NodeJS style callbacks or using different callbacks in Promise-style.\n\n```typescript\nimport { Result, Ok, Err } from 'stardust-types/result';\n\n// TODO\n```\n\nSee also: [test/result.ts](test/result.ts)\n\n### Either\u003cItemA, ItemB\u003e\n\nThe either type is similar to result but preffered for another usecases.\n\n```typescript\nimport { Either, A, B } from 'stardust-types/either';\n\n// TODO\n```\n\nSee also: [test/either.ts](test/either.ts)\n\n### Future\u003cItem, Error\u003e\n\nThe future type is intended for representing results which cannot be given at same moment when it requested.\n\n```typescript\nimport { Task, Future, oneshot } from 'stardust-types/future';\n\nconst [task, future] = oneshot\u003cnumber, string\u003e();\n\nlet timer;\ntask.start(() =\u003e {\n    timer = setTimeout(() =\u003e {\n        task.done(123);\n        // end.fail(\"Something went wrong\");\n    }, 1000);\n}).abort(() =\u003e {\n    clearTimeout(timer);\n});\n\nfuture\n    .map(a =\u003e a * a)\n    .map_err(e =\u003e new Error(e))\n    .end(res =\u003e {\n        res.map_or_else(\n            err =\u003e { throw err; },\n            val =\u003e {\n                console.log(`The number is: ${val}`);\n            }\n        );\n    })\n    .start();\n\n// prints '123' if not aborted within 1 sec\n// setTimeout(() =\u003e { future.abort(); }, 500);\n```\n\nSee also: [test/future.ts](test/future.ts)\n\n### Stream\u003cItem, Error\u003e _(TODO)_\n\n```typescript\nimport { Sink, Stream, channel } from 'stardust-types/stream';\n\n// TODO\n```\n\n## Implemented functions\n\n### timeout(msec: number): Future\u003cundefined, undefined\u003e\n\n```typescript\nimport { timeout } from 'stardust-types/timer';\n\nconst future = timeout(1000, Ok(\"Hello\"))\n    .map(phrase =\u003e `${phrase}!!!`)\n    .end(res =\u003e { console.log(res.unwrap()); })\n    .start();\n// prints 'Hello!!!' if not aborted within 1 sec\n// setTimeout(() =\u003e { future.abort(); }, 500);\n```\n\nSee also: [test/timer.ts](test/timer.ts)\n\n### interval(msec: number): Stream\u003cundefined, undefined\u003e _(TODO)_\n\n```typescript\nimport { interval } from 'stardust-types/timer';\n\ninterval(1000)\n    .map(() =\u003e \n```\n\n### request(Request): Future\u003cResponse, ResponseError\u003e _(TODO)_\n\n```typescript\nimport { request } from 'stardust-types/request';\n\n// TODO\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatyo%2Fstardust-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatyo%2Fstardust-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatyo%2Fstardust-types/lists"}