{"id":20771300,"url":"https://github.com/ootidea/result-type-ts","last_synced_at":"2025-04-07T14:12:33.053Z","repository":{"id":180939586,"uuid":"665943620","full_name":"ootidea/result-type-ts","owner":"ootidea","description":"A TypeScript library for the Result type.","archived":false,"fork":false,"pushed_at":"2024-12-14T00:40:53.000Z","size":215,"stargazers_count":36,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T12:09:39.874Z","etag":null,"topics":["library","monad","npm-package","result-type","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/result-type-ts","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ootidea.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":"2023-07-13T10:51:11.000Z","updated_at":"2025-01-24T10:37:06.000Z","dependencies_parsed_at":"2023-07-27T01:55:54.625Z","dependency_job_id":"f8221457-c720-497b-b703-762ba2bced6b","html_url":"https://github.com/ootidea/result-type-ts","commit_stats":{"total_commits":95,"total_committers":2,"mean_commits":47.5,"dds":"0.010526315789473717","last_synced_commit":"c83105975d971a87b90faaefd4d310bace806297"},"previous_names":["ootidea/ts-result-type","ootidea/result-type-ts"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Fresult-type-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Fresult-type-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Fresult-type-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ootidea%2Fresult-type-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ootidea","download_url":"https://codeload.github.com/ootidea/result-type-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666014,"owners_count":20975788,"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":["library","monad","npm-package","result-type","typescript"],"created_at":"2024-11-17T12:14:26.550Z","updated_at":"2025-04-07T14:12:33.022Z","avatar_url":"https://github.com/ootidea.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eresult-type-ts\u003c/h1\u003e\n\nA modern TypeScript library for the so-called Result type.\n\n## Features\n- 0 dependencies\n- Provides many utility functions about the Result type\n- Well-tested\n- Works on both browsers and Node.js\n- Strict type inference\n\n## Usage\n\nHere's a simple example of how to use this library:\n\n```ts\nimport { Result } from 'result-type-ts'\n\nconst result: Result\u003cnumber, string\u003e = Math.random() \u003c 0.5 ? Result.success(123) : Result.failure('error')\n\nif (result.isSuccess) {\n  console.log(result.value) // 123\n} else {\n  console.log(result.error) // error\n}\n```\n\n## API\n\n### Functions\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.success(value)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T\u0026gt;(value: T) =\u003e Result.Success\u0026lt;T\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eCreates a successful result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.value) // 123\nconsole.log(result.isSuccess) // true\nconsole.log(result.isFailure) // false\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.failure(error)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;E\u0026gt;(error: E) =\u0026gt; Result.Failure\u0026lt;E\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eCreates a failed result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.failure('error')\nconsole.log(result.error) // error\nconsole.log(result.isFailure) // true\nconsole.log(result.isSuccess) // false\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.tryCatch(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T\u0026gt;(f: () =\u0026gt; T) =\u0026gt; Result\u0026lt;T, unknown\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eIf the given function returns a value, a successful result is created. If it throws an exception, a failed result is created.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.tryCatch(() =\u003e 123)\nconsole.log(result.value) // 123\n\nconst result2 = Result.tryCatch(() =\u003e {\n  throw 'error'\n})\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.fromNullish(value)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n     \u003ctd\u003e\u003ccode\u003e\u0026lt;T\u0026gt;(value: T | null | undefined) =\u0026gt; Result\u0026lt;T, null | undefined\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eConvert a nullish value to a Result value.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.fromNullish(123);\nconsole.log(result.value) // 123\n\nconst result2 = Result.fromNullish(null);\nconsole.log(result2.error) // null\nconsole.log(result2.isFailure) // true\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.fromPromise(promise)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T\u0026gt;(promise: PromiseLike\u0026lt;T\u0026gt;) =\u0026gt; Promise\u0026lt;Result\u0026lt;T\u0026gt;\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eConvert a Promise value to a Result value.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = await Result.fromPromise(Promise.resolve(123))\nconsole.log(result.value) // 123\n\nconst result2 = await Result.fromPromise(Promise.reject('error'))\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.all(results)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T, E\u0026gt;(results: Result\u0026lt;T, E\u0026gt;[]) =\u0026gt; Result\u0026lt;T[], E\u0026gt;\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eConverts an array of Results into a single Result. If all results are successful, it returns a successful result of an array of values. Otherwise, it returns the first failed result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = await Result.all([Result.success(123), Result.success(456)])\nconsole.log(result.value) // 123\n\nconst result2 = await Result.all([Result.success(123), Result.failure('error')])\nconsole.log(result2.error) // error\n\nconst result3 = await Result.all([Result.failure('error'), Result.failure('error2')])\nconsole.log(result3.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n### Types\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.Success\u0026lt;T\u0026gt;\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\nRepresents a successful result type with a payload of type \u003ccode\u003eT\u003c/code\u003e.\n\n#### Example\n```ts\nconst result: Result.Success\u003cnumber\u003e = Result.success(123)\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult.Failure\u0026lt;E\u0026gt;\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\nRepresents a failed result type with an error value of type \u003ccode\u003eE\u003c/code\u003e.\n\n#### Example\n```ts\nconst result: Result.Failure\u003cstring\u003e = Result.failure('error')\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eResult\u0026lt;T, E\u0026gt;\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\nShorthand for \u003ccode\u003eResult.Success\u0026lt;T\u0026gt; | Result.Failure\u0026lt;E\u0026gt;\u003c/code\u003e type. \u003ccode\u003eE\u003c/code\u003e is optional with a default value of \u003ccode\u003eunknown\u003c/code\u003e.\n\n#### Example\n```ts\nconst result: Result\u003cnumber, string\u003e = Math.random() \u003e 0.5 ? Result.success(123) : Result.failure('error')\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n### Properties\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.value\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eT | undefined\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eThe payload of the successful result. If the result is a failure, it's \u003ccode\u003eundefined\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.value) // 123\n\nconst result2 = Result.failure('error')\nconsole.log(result2.value) // undefined\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.error\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eE | undefined\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eThe payload of the failed result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.error) // undefined\n\nconst result2 = Result.failure('error')\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.isSuccess\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eWhether it is a successful result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.isSuccess) // true\n\nconst result2 = Result.failure('error')\nconsole.log(result2.isSuccess) // false\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.isFailure\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eboolean\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eWhether it is a failed result.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.isFailure) // false\n\nconst result2 = Result.failure('error')\nconsole.log(result2.isFailure) // true\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n### Methods\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.getOrThrow()\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e() =\u003e T\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eReturns \u003ccode\u003ethis.value\u003c/code\u003e if it's a successful result, otherwise throws \u003ccode\u003ethis.error\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.getOrThrow()) // 123\n\nconst result2 = Result.failure('error')\ntry {\n  result2.getOrThrow()\n} catch (e) {\n  console.log(e) // error\n}\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.toUnion()\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e() =\u003e T | E\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eReturns the payload of the result value.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.toUnion()) // 123\n\nconst result2 = Result.failure('error')\nconsole.log(result2.toUnion()) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.ifSuccess(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T2\u0026gt;(f: (value: T) =\u0026gt; T2) =\u0026gt; T2 | undefined\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eApplies the given function to \u003ccode\u003ethis.value\u003c/code\u003e if it's a successful result, otherwise returns \u003ccode\u003eundefined\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.ifSuccess((value) =\u003e value * 2)) // 246\n\nconst result2 = Result.failure('error')\nconsole.log(result2.ifSuccess((value) =\u003e value * 2)) // undefined\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.ifFailure(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;E2\u0026gt;(f: (error: E) =\u0026gt; E2) =\u0026gt; E2 | undefined\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eApplies the given function to \u003ccode\u003eresult.error\u003c/code\u003e if it's a failed result, otherwise returns \u003ccode\u003eundefined\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.ifFailure((error) =\u003e error + '!')) // undefined\n\nconst result2 = Result.failure('error')\nconsole.log(result2.ifFailure((error) =\u003e error + '!')) // error!\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.match(f, g)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T2, E2\u003e((value: T) =\u003e T2, (error: E) =\u003e E2) =\u003e T2 | E2\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eReturn the result of applying one of the given functions to the payload.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123)\nconsole.log(result.match((value) =\u003e value * 2, (error) =\u003e error + '!')) // 246\n\nconst result2 = Result.failure('error')\nconsole.log(result2.match((value) =\u003e value * 2, (error) =\u003e error + '!')) // error!\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.map(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T2\u003e(f: (value: T) =\u003e T2) =\u003e Result\u0026lt;T2, E\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eCreates a Result value by modifying the payload of the successful result using the given function\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123).map((value) =\u003e value * 2)\nconsole.log(result.value) // 246\n\nconst result2 = Result.failure('error').map((value) =\u003e value * 2)\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.mapError(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;E2\u003e(f: (error: E) =\u003e E2) =\u003e Result\u0026lt;T, E2\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eCreates a Result value by modifying the payload of the failed result using the given function\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123).mapError((error) =\u003e error + '!')\nconsole.log(result.value) // 123\n\nconst result2 = Result.failure('error').mapError((error) =\u003e error + '!')\nconsole.log(result2.error) // error!\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.flatMap(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T2, E2\u003e(f: (value: T) =\u003e Result\u0026lt;T2, E2\u003e) =\u003e Result\u0026lt;T2, E | E2\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eMaps the payload of the successful result and flattens the nested Result type.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(123).flatMap((value) =\u003e Result.success(value * 2))\nconsole.log(result.value) // 246\n\nconst result2 = Result.failure('error').flatMap((value) =\u003e Result.failure(value * 2))\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.flatMapAsync(f)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;T2, E2\u003e(f: (value: T) =\u003e Result\u0026lt;T2, E2\u003e) =\u003e Result\u0026lt;T2, E | E2\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eMaps the payload of the successful result and flattens the nested async Result function.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = await Result.success(123).flatMapAsync(async (value) =\u003e Result.success(value * 2))\nconsole.log(result.value) // 246\n\nconst result2 = await Result.failure('error').flatMapAsync(async (value) =\u003e Result.failure(value * 2))\nconsole.log(result2.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.flatten()\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e() =\u003e Result\u0026lt;T, E | E2\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eFlattens the nested Result type. For instance, it converts \u003ccode\u003eResult\u0026lt;Result\u0026lt;T, E\u003e, E2\u003e\u003c/code\u003e into \u003ccode\u003eResult\u0026lt;T, E | E2\u003e\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result = Result.success(Result.success(123)).flatten()\nconsole.log(result.value) // 246\n\nconst result2 = Result.success(Result.failure('error')).flatten()\nconsole.log(result2.error) // error\n\nconst result3 = Result.failure('error').flatten()\nconsole.log(result3.error) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003eresult.assertErrorInstanceOf(ctor)\u003c/code\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eType\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e\u0026lt;C extends abstract new (..._: any) =\u003e any\u003e(ctor: C) =\u003e Result\u0026lt;T, InstanceType\u0026lt;C\u003e\u003e\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cb\u003eDescription\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eAsserts that the error value is an instance of the given class. If the error value is not an instance of the given class, it throws \u003ccode\u003eTypeError\u003c/code\u003e.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Example\n```ts\nconst result: Result\u003cnumber, Error\u003e = Result.tryCatch(() =\u003e {\n  if (Math.random() \u003e= 0) {\n    throw new Error('error')\n  } else {\n    return 123\n  }\n}).assertErrorInstanceOf(Error)\nconsole.log(result.isFailure \u0026\u0026 result.error.message) // error\n```\n\n\u003cbr/\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Footidea%2Fresult-type-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Footidea%2Fresult-type-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Footidea%2Fresult-type-ts/lists"}