{"_id":"@achii/ts-results","name":"@achii/ts-results","dist-tags":{"latest":"3.3.0"},"versions":{"3.3.0":{"name":"@achii/ts-results","version":"3.3.0","description":"A typescript implementation of Rust's Result and Option objects.","scripts":{"build":"npm run clean && npm run build:ts && npm run build:copy","build:ts":"tsc -p tsconfig.json && tsc -p tsconfig.json -m esnext --outDir dist/esm/ -d false -declarationMap false","build:copy":"copyfiles README.md LICENSE src/package.json dist --flat && copyfiles src/rxjs-operators/package.json dist --up 1","clean":"rm -rf dist","test":"jest","format":"prettier . --write"},"repository":{"type":"git","url":"git+https://github.com/achi-co/ts-results.git"},"keywords":[],"author":{"name":"mrbrown"},"license":"ISC","devDependencies":{"@types/jest":"^26.0.22","conditional-type-checks":"^1.0.5","copyfiles":"^2.4.1","jest":"^26.6.3","prettier":"^2.2.1","rxjs":"^6.6.7","ts-jest":"^26.5.4","tslib":"^2.1.0","typescript":"^4.2"},"bugs":{"url":"https://github.com/achi-co/ts-results/issues"},"homepage":"https://github.com/achi-co/ts-results#readme","main":"dist/index.js","directories":{"test":"test"},"dependencies":{"abab":"^2.0.5","acorn":"^8.1.0","acorn-globals":"^6.0.0","acorn-walk":"^7.2.0","ajv":"^6.12.6","ansi-escapes":"^4.3.2","ansi-regex":"^5.0.0","ansi-styles":"^4.2.1","anymatch":"^3.1.1","argparse":"^1.0.10","arr-diff":"^4.0.0","arr-flatten":"^1.1.0","arr-union":"^3.1.0","array-unique":"^0.3.2","asn1":"^0.2.4","assert-plus":"^1.0.0","assign-symbols":"^1.0.0","asynckit":"^0.4.0","atob":"^2.1.2","aws-sign2":"^0.7.0","aws4":"^1.11.0","babel-jest":"^26.6.3","babel-plugin-istanbul":"^6.0.0","babel-plugin-jest-hoist":"^26.6.2","babel-preset-current-node-syntax":"^1.0.1","babel-preset-jest":"^26.6.2","balanced-match":"^1.0.0","base":"^0.11.2","bcrypt-pbkdf":"^1.0.2","brace-expansion":"^1.1.11","braces":"^3.0.2","browser-process-hrtime":"^1.0.0","browserslist":"^4.16.3","bs-logger":"^0.2.6","bser":"^2.1.1","buffer-from":"^1.1.1","cache-base":"^1.0.1","callsites":"^3.1.0","camelcase":"^5.3.1","caniuse-lite":"^1.0.30001204","capture-exit":"^2.0.0","caseless":"^0.12.0","chalk":"^4.1.0","char-regex":"^1.0.2","ci-info":"^2.0.0","cjs-module-lexer":"^0.6.0","class-utils":"^0.3.6","cliui":"^7.0.4","co":"^4.6.0","collect-v8-coverage":"^1.0.1","collection-visit":"^1.0.0","color-convert":"^2.0.1","color-name":"^1.1.4","colorette":"^1.2.2","combined-stream":"^1.0.8","component-emitter":"^1.3.0","concat-map":"^0.0.1","convert-source-map":"^1.7.0","copy-descriptor":"^0.1.1","core-util-is":"^1.0.2","cross-spawn":"^7.0.3","cssom":"^0.4.4","cssstyle":"^2.3.0","dashdash":"^1.14.1","data-urls":"^2.0.0","debug":"^4.3.1","decamelize":"^1.2.0","decimal.js":"^10.2.1","decode-uri-component":"^0.2.0","deep-is":"^0.1.3","deepmerge":"^4.2.2","define-property":"^2.0.2","delayed-stream":"^1.0.0","detect-newline":"^3.1.0","diff-sequences":"^26.6.2","domexception":"^2.0.1","ecc-jsbn":"^0.1.2","electron-to-chromium":"^1.3.701","emittery":"^0.7.2","emoji-regex":"^8.0.0","end-of-stream":"^1.4.4","error-ex":"^1.3.2","escalade":"^3.1.1","escape-string-regexp":"^2.0.0","escodegen":"^2.0.0","esprima":"^4.0.1","estraverse":"^5.2.0","esutils":"^2.0.3","exec-sh":"^0.3.6","execa":"^4.1.0","exit":"^0.1.2","expand-brackets":"^2.1.4","expect":"^26.6.2","extend":"^3.0.2","extend-shallow":"^3.0.2","extglob":"^2.0.4","extsprintf":"^1.3.0","fast-deep-equal":"^3.1.3","fast-json-stable-stringify":"^2.1.0","fast-levenshtein":"^2.0.6","fb-watchman":"^2.0.1","fill-range":"^7.0.1","find-up":"^4.1.0","for-in":"^1.0.2","forever-agent":"^0.6.1","form-data":"^2.3.3","fragment-cache":"^0.2.1","fs.realpath":"^1.0.0","fsevents":"^2.3.2","function-bind":"^1.1.1","gensync":"^1.0.0-beta.2","get-caller-file":"^2.0.5","get-package-type":"^0.1.0","get-stream":"^5.2.0","get-value":"^2.0.6","getpass":"^0.1.7","glob":"^7.1.6","globals":"^11.12.0","graceful-fs":"^4.2.6","growly":"^1.3.0","har-schema":"^2.0.0","har-validator":"^5.1.5","has":"^1.0.3","has-flag":"^4.0.0","has-value":"^1.0.0","has-values":"^1.0.0","hosted-git-info":"^2.8.8","html-encoding-sniffer":"^2.0.1","html-escaper":"^2.0.2","http-signature":"^1.2.0","human-signals":"^1.1.1","iconv-lite":"^0.4.24","import-local":"^3.0.2","imurmurhash":"^0.1.4","inflight":"^1.0.6","inherits":"^2.0.4","is-accessor-descriptor":"^1.0.0","is-arrayish":"^0.2.1","is-buffer":"^1.1.6","is-ci":"^2.0.0","is-core-module":"^2.2.0","is-data-descriptor":"^1.0.0","is-descriptor":"^1.0.2","is-docker":"^2.1.1","is-extendable":"^1.0.1","is-fullwidth-code-point":"^3.0.0","is-generator-fn":"^2.1.0","is-number":"^7.0.0","is-plain-object":"^2.0.4","is-potential-custom-element-name":"^1.0.0","is-stream":"^2.0.0","is-typedarray":"^1.0.0","is-windows":"^1.0.2","is-wsl":"^2.2.0","isarray":"^0.0.1","isexe":"^2.0.0","isobject":"^3.0.1","isstream":"^0.1.2","istanbul-lib-coverage":"^3.0.0","istanbul-lib-instrument":"^4.0.3","istanbul-lib-report":"^3.0.0","istanbul-lib-source-maps":"^4.0.0","istanbul-reports":"^3.0.2","jest-changed-files":"^26.6.2","jest-cli":"^26.6.3","jest-config":"^26.6.3","jest-diff":"^26.6.2","jest-docblock":"^26.0.0","jest-each":"^26.6.2","jest-environment-jsdom":"^26.6.2","jest-environment-node":"^26.6.2","jest-get-type":"^26.3.0","jest-haste-map":"^26.6.2","jest-jasmine2":"^26.6.3","jest-leak-detector":"^26.6.2","jest-matcher-utils":"^26.6.2","jest-message-util":"^26.6.2","jest-mock":"^26.6.2","jest-pnp-resolver":"^1.2.2","jest-regex-util":"^26.0.0","jest-resolve":"^26.6.2","jest-resolve-dependencies":"^26.6.3","jest-runner":"^26.6.3","jest-runtime":"^26.6.3","jest-serializer":"^26.6.2","jest-snapshot":"^26.6.2","jest-util":"^26.6.2","jest-validate":"^26.6.2","jest-watcher":"^26.6.2","jest-worker":"^26.6.2","js-tokens":"^4.0.0","js-yaml":"^3.14.1","jsbn":"^0.1.1","jsdom":"^16.5.2","jsesc":"^2.5.2","json-parse-even-better-errors":"^2.3.1","json-schema":"^0.2.3","json-schema-traverse":"^0.4.1","json-stringify-safe":"^5.0.1","json5":"^2.1.3","jsprim":"^1.4.1","kind-of":"^6.0.3","kleur":"^3.0.3","leven":"^3.1.0","levn":"^0.3.0","lines-and-columns":"^1.1.6","locate-path":"^5.0.0","lodash":"^4.17.21","lru-cache":"^6.0.0","make-dir":"^3.1.0","make-error":"^1.3.6","makeerror":"^1.0.11","map-cache":"^0.2.2","map-visit":"^1.0.0","merge-stream":"^2.0.0","micromatch":"^4.0.2","mime-db":"^1.46.0","mime-types":"^2.1.29","mimic-fn":"^2.1.0","minimatch":"^3.0.4","minimist":"^1.2.5","mixin-deep":"^1.3.2","mkdirp":"^1.0.4","ms":"^2.1.2","nanomatch":"^1.2.13","natural-compare":"^1.4.0","nice-try":"^1.0.5","node-int64":"^0.4.0","node-modules-regexp":"^1.0.0","node-notifier":"^8.0.2","node-releases":"^1.1.71","noms":"^0.0.0","normalize-package-data":"^2.5.0","normalize-path":"^3.0.0","npm-run-path":"^4.0.1","nwsapi":"^2.2.0","oauth-sign":"^0.9.0","object-copy":"^0.1.0","object-visit":"^1.0.1","object.pick":"^1.3.0","once":"^1.4.0","onetime":"^5.1.2","optionator":"^0.8.3","p-each-series":"^2.2.0","p-finally":"^1.0.0","p-limit":"^2.3.0","p-locate":"^4.1.0","p-try":"^2.2.0","parse-json":"^5.2.0","parse5":"^6.0.1","pascalcase":"^0.1.1","path-exists":"^4.0.0","path-is-absolute":"^1.0.1","path-key":"^3.1.1","path-parse":"^1.0.6","performance-now":"^2.1.0","picomatch":"^2.2.2","pirates":"^4.0.1","pkg-dir":"^4.2.0","posix-character-classes":"^0.1.1","prelude-ls":"^1.1.2","pretty-format":"^26.6.2","process-nextick-args":"^2.0.1","prompts":"^2.4.0","psl":"^1.8.0","pump":"^3.0.0","punycode":"^2.1.1","qs":"^6.5.2","react-is":"^17.0.2","read-pkg":"^5.2.0","read-pkg-up":"^7.0.1","readable-stream":"^1.0.34","regex-not":"^1.0.2","remove-trailing-separator":"^1.1.0","repeat-element":"^1.1.3","repeat-string":"^1.6.1","request":"^2.88.2","request-promise-core":"^1.1.4","request-promise-native":"^1.0.9","require-directory":"^2.1.1","require-main-filename":"^2.0.0","resolve":"^1.20.0","resolve-cwd":"^3.0.0","resolve-from":"^5.0.0","resolve-url":"^0.2.1","ret":"^0.1.15","rimraf":"^3.0.2","rsvp":"^4.8.5","safe-buffer":"^5.1.2","safe-regex":"^1.1.0","safer-buffer":"^2.1.2","sane":"^4.1.0","saxes":"^5.0.1","semver":"^6.3.0","set-blocking":"^2.0.0","set-value":"^2.0.1","shebang-command":"^2.0.0","shebang-regex":"^3.0.0","shellwords":"^0.1.1","signal-exit":"^3.0.3","sisteransi":"^1.0.5","slash":"^3.0.0","snapdragon":"^0.8.2","snapdragon-node":"^2.1.1","snapdragon-util":"^3.0.1","source-map":"^0.6.1","source-map-resolve":"^0.5.3","source-map-support":"^0.5.19","source-map-url":"^0.4.1","spdx-correct":"^3.1.1","spdx-exceptions":"^2.3.0","spdx-expression-parse":"^3.0.1","spdx-license-ids":"^3.0.7","split-string":"^3.1.0","sprintf-js":"^1.0.3","sshpk":"^1.16.1","stack-utils":"^2.0.3","static-extend":"^0.1.2","stealthy-require":"^1.1.1","string-length":"^4.0.2","string-width":"^4.2.2","string_decoder":"^0.10.31","strip-ansi":"^6.0.0","strip-bom":"^4.0.0","strip-eof":"^1.0.0","strip-final-newline":"^2.0.0","supports-color":"^7.1.0","supports-hyperlinks":"^2.1.0","symbol-tree":"^3.2.4","terminal-link":"^2.1.1","test-exclude":"^6.0.0","throat":"^5.0.0","through2":"^2.0.5","tmpl":"^1.0.4","to-fast-properties":"^2.0.0","to-object-path":"^0.3.0","to-regex":"^3.0.2","to-regex-range":"^5.0.1","tough-cookie":"^4.0.0","tr46":"^2.0.2","tunnel-agent":"^0.6.0","tweetnacl":"^0.14.5","type-check":"^0.3.2","type-detect":"^4.0.8","type-fest":"^0.21.3","typedarray-to-buffer":"^3.1.5","union-value":"^1.0.1","universalify":"^0.1.2","unset-value":"^1.0.0","untildify":"^4.0.0","uri-js":"^4.4.1","urix":"^0.1.0","use":"^3.1.1","util-deprecate":"^1.0.2","uuid":"^8.3.2","v8-to-istanbul":"^7.1.0","validate-npm-package-license":"^3.0.4","verror":"^1.10.0","w3c-hr-time":"^1.0.2","w3c-xmlserializer":"^2.0.0","walker":"^1.0.7","webidl-conversions":"^6.1.0","whatwg-encoding":"^1.0.5","whatwg-mimetype":"^2.3.0","whatwg-url":"^8.5.0","which":"^2.0.2","which-module":"^2.0.0","word-wrap":"^1.2.3","wrap-ansi":"^7.0.0","wrappy":"^1.0.2","write-file-atomic":"^3.0.3","ws":"^7.4.4","xml-name-validator":"^3.0.0","xmlchars":"^2.2.0","xtend":"^4.0.2","y18n":"^5.0.5","yallist":"^4.0.0","yargs":"^16.2.0","yargs-parser":"^20.2.7"},"types":"./dist/index.d.ts","_id":"@achii/ts-results@3.3.0","gitHead":"910789d42f2cc8469f5fad2b80b1844e0c063269","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-WcBQcLmJHg2rSR7NvEelLq5QKQAKkEvRB0jURnWPMn7qA2mz4kN5XrWirG5GHYVxlaW6WL0sSrGePAZYeW10Yg==","shasum":"1f4bd987f6e40a1b032382aac39311d22aaf5dae","tarball":"https://registry.npmjs.org/@achii/ts-results/-/ts-results-3.3.0.tgz","fileCount":43,"unpackedSize":141839,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDHWAVVLkIawoM9tcrlndUc84Q5G+r2HhvzPfY9N7OxNAIhAOQULoABc3OIvC6vewZVIDv62oSWCnTv9cuT+CyoAQxX"}]},"_npmUser":{"name":"mrbrown","email":"bite6210@gmail.com"},"maintainers":[{"name":"mrbrown","email":"bite6210@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ts-results_3.3.0_1734270296820_0.2533126468657705"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-15T13:44:56.730Z","3.3.0":"2024-12-15T13:44:57.035Z","modified":"2024-12-15T13:44:57.333Z"},"maintainers":[{"name":"mrbrown","email":"bite6210@gmail.com"}],"description":"A typescript implementation of Rust's Result and Option objects.","homepage":"https://github.com/achi-co/ts-results#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/achi-co/ts-results.git"},"author":{"name":"mrbrown"},"bugs":{"url":"https://github.com/achi-co/ts-results/issues"},"license":"ISC","readme":"# ts-results\n\nA typescript implementation of Rust's [Result](https://doc.rust-lang.org/std/result/)\nand [Option](https://doc.rust-lang.org/std/option/) objects.\n\nBrings compile-time error checking and optional values to typescript.\n\n## Contents\n\n-   [Installation](#installation)\n-   [Example](#example)\n    -   [Result Example](#result-example)\n    -   [Option Example](#option-example)\n-   [Usage](#usage)\n    -   [Creation](#creation)\n    -   [Type Safety](#type-safety)\n    -   [Unwrap](#unwrap)\n    -   [Expect](#expect)\n    -   [ExpectErr](#expecterr)\n    -   [Map, MapErr](#map-and-maperr)\n    -   [andThen](#andthen)\n    -   [Else](#else)\n    -   [UnwrapOr](#unwrapor)\n    -   [Empty](#empty)\n    -   [Combining Results](#combining-results)\n        -   [Result.all](#result-all)\n        -   [Result.any](#result-any)\n-   [Usage with rxjs](#usage-with-rxjs)\n    -   [resultMap](#resultmap)\n    -   [resultMapErr](#resultmaperr)\n    -   [resultMapTo](#resultmapto)\n    -   [resultMapErrTo](#resultmapto)\n    -   [elseMap](#elsemap)\n    -   [elseMapTo](#elsemapto)\n    -   [resultSwitchMap, resultMergeMap](#resultswitchmap-and-resultmergemap)\n    -   [filterResultOk](#filterresultok)\n    -   [filterResultErr](#filterresulterr)\n\n## Installation\n\n```bash\n$ npm install ts-results\n```\n\nor\n\n```bash\n$ yarn add ts-results\n```\n\n## Example\n\n### Result Example\n\nConvert this:\n\n```typescript\nimport { existsSync, readFileSync } from 'fs';\n\nfunction readFile(path: string): string {\n    if (existsSync(path)) {\n        return readFileSync(path);\n    } else {\n        // Callers of readFile have no way of knowing the function can fail\n        throw new Error('invalid path');\n    }\n}\n\n// This line may fail unexpectedly without warnings from typescript\nconst text = readFile('test.txt');\n```\n\nTo this:\n\n```typescript\nimport { existsSync, readFileSync } from 'fs';\nimport { Ok, Err, Result } from 'ts-results';\n\nfunction readFile(path: string): Result<string, 'invalid path'> {\n    if (existsSync(path)) {\n        return new Ok(readFileSync(path)); // new is optional here\n    } else {\n        return new Err('invalid path'); // new is optional here\n    }\n}\n\n// Typescript now forces you to check whether you have a valid result at compile time.\nconst result = readFile('test.txt');\nif (result.ok) {\n    // text contains the file's content\n    const text = result.val;\n} else {\n    // err equals 'invalid path'\n    const err = result.val;\n}\n```\n\n### Option Example\n\nConvert this:\n\n```typescript\ndeclare function getLoggedInUsername(): string | undefined;\n\ndeclare function getImageURLForUsername(username: string): string | undefined;\n\nfunction getLoggedInImageURL(): string | undefined {\n    const username = getLoggedInUsername();\n    if (!username) {\n        return undefined;\n    }\n\n    return getImageURLForUsername(username);\n}\n\nconst stringUrl = getLoggedInImageURL();\nconst optionalUrl = stringUrl ? new URL(stringUrl) : undefined;\nconsole.log(optionalUrl);\n```\n\nTo this:\n\n```typescript\nimport { Option, Some, None } from 'ts-results';\n\ndeclare function getLoggedInUsername(): Option<string>;\n\ndeclare function getImageForUsername(username: string): Option<string>;\n\nfunction getLoggedInImage(): Option<string> {\n    return getLoggedInUsername().andThen(getImageForUsername);\n}\n\nconst optionalUrl = getLoggedInImage().map((url) => new URL(stringUrl));\nconsole.log(optionalUrl); // Some(URL('...'))\n\n// To extract the value, do this:\nif (optionalUrl.some) {\n    const url: URL = optionalUrl.val;\n}\n```\n\n## Usage\n\n```typescript\nimport { Result, Err, Ok } from 'ts-results';\n```\n\n#### Creation\n\n```typescript\nlet okResult: Result<number, Error> = Ok(10);\nlet errorResult: Result<number, Error> = Err(new Error('bad number!'));\n```\n\n#### Type Safety\n_Note: Typescript currently has a [bug](https://github.com/microsoft/TypeScript/issues/10564), making this type narrowing only work when `strictNullChecks` is turned on._\n```typescript\nlet result: Result<number, Error> = Ok(1);\nif (result.ok) {\n    // Typescript knows that result.val is a number because result.ok was true\n    let number = result.val + 1;\n} else {\n    // Typescript knows that result.val is an `Error` because result.ok was false\n    console.error(result.val.message);\n}\n\nif (result.err) {\n    // Typescript knows that result.val is an `Error` because result.err was true\n    console.error(result.val.message);\n} else {\n    // Typescript knows that result.val is a number because result.err was false\n    let number = result.val + 1;\n}\n```\n\n### Stack Trace\n\nA stack trace is generated when an `Err` is created.\n\n```typescript\nlet error = Err('Uh Oh');\nlet stack = error.stack;\n```\n\n#### Unwrap\n\n```typescript\nlet goodResult = new Ok(1);\nlet badResult = new Err(new Error('something went wrong'));\n\ngoodResult.unwrap(); // 1\nbadResult.unwrap(); // throws Error(\"something went wrong\")\n```\n\n#### Expect\n\n```typescript\nlet goodResult = Ok(1);\nlet badResult = Err(new Error('something went wrong'));\n\ngoodResult.expect('goodResult should be a number'); // 1\nbadResult.expect('badResult should be a number'); // throws Error(\"badResult should be a number - Error: something went wrong\")\n```\n\n#### ExpectErr\n\n```typescript\nlet goodResult = Ok(1);\nlet badResult = Err(new Error('something went wrong'));\n\ngoodResult.expect('goodResult should not be a number'); // throws Error(\"goodResult should not be a number\")\nbadResult.expect('badResult should not be a number'); // new Error('something went wrong')\n```\n\n\n#### Map and MapErr\n\n```typescript\nlet goodResult = Ok(1);\nlet badResult = Err(new Error('something went wrong'));\n\ngoodResult.map((num) => num + 1).unwrap(); // 2\nbadResult.map((num) => num + 1).unwrap(); // throws Error(\"something went wrong\")\n\ngoodResult\n    .map((num) => num + 1)\n    .mapErr((err) => new Error('mapped'))\n    .unwrap(); // 2\nbadResult\n    .map((num) => num + 1)\n    .mapErr((err) => new Error('mapped'))\n    .unwrap(); // throws Error(\"mapped\")\n```\n\n#### andThen\n\n```typescript\nlet goodResult = Ok(1);\nlet badResult = Err(new Error('something went wrong'));\n\ngoodResult.andThen((num) => new Ok(num + 1)).unwrap(); // 2\nbadResult.andThen((num) => new Err(new Error('2nd error'))).unwrap(); // throws Error('something went wrong')\ngoodResult.andThen((num) => new Err(new Error('2nd error'))).unwrap(); // throws Error('2nd error')\n\ngoodResult\n    .andThen((num) => new Ok(num + 1))\n    .mapErr((err) => new Error('mapped'))\n    .unwrap(); // 2\nbadResult\n    .andThen((num) => new Err(new Error('2nd error')))\n    .mapErr((err) => new Error('mapped'))\n    .unwrap(); // throws Error('mapped')\ngoodResult\n    .andThen((num) => new Err(new Error('2nd error')))\n    .mapErr((err) => new Error('mapped'))\n    .unwrap(); // thros Error('mapped')\n```\n\n#### Else\n\nDeprecated in favor of unwrapOr\n\n#### UnwrapOr\n\n```typescript\nlet goodResult = Ok(1);\nlet badResult = Err(new Error('something went wrong'));\n\ngoodResult.unwrapOr(5); // 1\nbadResult.unwrapOr(5); // 5\n```\n\n#### Empty\n\n```typescript\nfunction checkIsValid(isValid: boolean): Result<void, Error> {\n    if (isValid) {\n        return Ok.EMPTY;\n    } else {\n        return new Err(new Error('Not valid'));\n    }\n}\n```\n\n#### Combining Results\n\n`ts-results` has two helper functions for operating over n `Result` objects.\n\n##### Result.all\n\nEither returns all of the `Ok` values, or the first `Err` value\n\n```typescript\nlet pizzaResult: Result<Pizza, GetPizzaError> = getPizzaSomehow();\nlet toppingsResult: Result<Toppings, GetToppingsError> = getToppingsSomehow();\n\nlet result = Result.all(pizzaResult, toppingsResult); // Result<[Pizza, Toppings], GetPizzaError | GetToppingsError>\n\nlet [pizza, toppings] = result.unwrap(); // pizza is a Pizza, toppings is a Toppings.  Could throw GetPizzaError or GetToppingsError.\n```\n\n##### Result.any\n\nEither returns the first `Ok` value, or all `Err` values\n\n```typescript\nlet url1: Result<string, Error1> = attempt1();\nlet url2: Result<string, Error2> = attempt2();\nlet url3: Result<string, Error3> = attempt3();\n\nlet result = Result.any(url1, url2, url3); // Result<string, Error1 | Error2 | Error3>\n\nlet url = result.unwrap(); // At least one attempt gave us a successful url\n```\n\n## Usage with rxjs\n\n#### resultMap\n\nAllows you to do the same actions as the normal [rxjs map](http://reactivex.io/documentation/operators/map.html)\noperator on a stream of Result objects.\n\n```typescript\nimport { of, Observable } from 'rxjs';\nimport { Ok, Err, Result } from 'ts-results';\nimport { resultMap } from 'ts-results/rxjs-operators';\n\nconst obs$: Observable<Result<number, Error>> = of(Ok(5), Err('uh oh'));\n\nconst greaterThanZero = obs$.pipe(\n    resultMap((number) => number > 0), // Doubles the value\n); // Has type Observable<Result<boolean, 'uh oh'>>\n\ngreaterThanZero.subscribe((result) => {\n    if (result.ok) {\n        console.log('Was greater than zero: ' + result.val);\n    } else {\n        console.log('Got Error Message: ' + result.val);\n    }\n});\n\n// Logs the following:\n// Got number: 10\n// Got Error Message: uh oh\n```\n\n#### resultMapErr\n\n```typescript\nimport { resultMapErr } from 'ts-results/rxjs-operators';\n```\n\nBehaves exactly the same as [resultMap](#resultmap), but maps the error value.\n\n#### resultMapTo\n\n```typescript\nimport { resultMapTo } from 'ts-results/rxjs-operators';\n```\n\nBehaves the same as [resultMap](#resultmap), but takes a value instead of a function.\n\n#### resultMapErrTo\n\n```typescript\nimport { resultMapErrTo } from 'ts-results/rxjs-operators';\n```\n\nBehaves the same as [resultMapErr](#resultmaperr), but takes a value instead of a function.\n\n#### elseMap\n\nAllows you to turn a stream of Result objects into a stream of values, transforming any errors into a value.\n\nSimilar to calling the [else](#else) function, but works on a stream of Result objects.\n\n```typescript\nimport { of, Observable } from 'rxjs';\nimport { Ok, Err, Result } from 'ts-results';\nimport { elseMap } from 'ts-results/rxjs-operators';\n\nconst obs$: Observable<Result<number, Error>> = of(Ok(5), Err(new Error('uh oh')));\n\nconst doubled = obs$.pipe(\n    elseMap((err) => {\n        console.log('Got error: ' + err.message);\n\n        return -1;\n    }),\n); // Has type Observable<number>\n\ndoubled.subscribe((number) => {\n    console.log('Got number: ' + number);\n});\n\n// Logs the following:\n// Got number: 5\n// Got error: uh oh\n// Got number: -1\n```\n\n#### elseMapTo\n\n```typescript\nimport { elseMapTo } from 'ts-results/rxjs-operators';\n```\n\nBehaves the same as [elseMap](#elsemap), but takes a value instead of a function.\n\n#### resultSwitchMap and resultMergeMap\n\nAllows you to do the same actions as the\nnormal [rxjs switchMap](https://www.learnrxjs.io/operators/transformation/switchmap.html)\nand [rxjs switchMap](https://www.learnrxjs.io/operators/transformation/mergemap.html) operator on a stream of Result\nobjects.\n\nMerging or switching from a stream of `Result<T, E>` objects onto a stream of `<T2>` objects turns the stream into a\nstream of `Result<T2, E>` objects.\n\nMerging or switching from a stream of `Result<T, E>` objects onto a stream of `Result<T2, E2>` objects turn the stream\ninto a stream of `Result<T2, E | T2>` objects.\n\n```typescript\nimport { of, Observable } from 'rxjs';\nimport { Ok, Err, Result } from 'ts-results';\nimport { resultMergeMap } from 'ts-results/rxjs-operators';\n\nconst obs$: Observable<Result<number, Error>> = of(new Ok(5), new Err(new Error('uh oh')));\n\nconst obs2$: Observable<Result<string, CustomError>> = of(new Ok('hi'), new Err(new CustomError('custom error')));\n\nconst test$ = obs$.pipe(\n    resultMergeMap((number) => {\n        console.log('Got number: ' + number);\n\n        return obs2$;\n    }),\n); // Has type Observable<Result<string, CustomError | Error>>\n\ntest$.subscribe((result) => {\n    if (result.ok) {\n        console.log('Got string: ' + result.val);\n    } else {\n        console.log('Got error: ' + result.val.message);\n    }\n});\n\n// Logs the following:\n// Got number: 5\n// Got string: hi\n// Got error: custom error\n// Got error: uh oh\n```\n\n#### filterResultOk\n\nConverts an `Observable<Result<T, E>>` to an `Observble<T>` by filtering out the Errs and mapping to the Ok values.\n\n```typescript\nimport { of, Observable } from 'rxjs';\nimport { Ok, Err, Result } from 'ts-results';\nimport { filterResultOk } from 'ts-results/rxjs-operators';\n\nconst obs$: Observable<Result<number, Error>> = of(new Ok(5), new Err(new Error('uh oh')));\n\nconst test$ = obs$.pipe(filterResultOk()); // Has type Observable<number>\n\ntest$.subscribe((result) => {\n    console.log('Got number: ' + result);\n});\n\n// Logs the following:\n// Got number: 5\n```\n\n#### filterResultErr\n\nConverts an `Observable<Result<T, E>>` to an `Observble<T>` by filtering out the Oks and mapping to the error values.\n\n```typescript\nimport { of, Observable } from 'rxjs';\nimport { Ok, Err, Result } from 'ts-results';\nimport { filterResultOk } from 'ts-results/rxjs-operators';\n\nconst obs$: Observable<Result<number, Error>> = of(new Ok(5), new Err(new Error('uh oh')));\n\nconst test$ = obs$.pipe(filterResultOk()); // Has type Observable<number>\n\ntest$.subscribe((result) => {\n    console.log('Got number: ' + result);\n});\n\n// Logs the following:\n// Got number: 5\n```\n","readmeFilename":"README.md"}