├── .babelrc ├── .config └── dotnet-tools.json ├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .editorconfig ├── .fantomasignore ├── .git-blame-ignore-revs ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── build.yml ├── .gitignore ├── .nvmrc ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── Ajira-logo.png ├── Directory.Build.props ├── Directory.Packages.props ├── Directory.Solution.targets ├── FsToolkit.ErrorHandling.sln ├── License ├── README.md ├── RELEASE_NOTES.md ├── benchmarks ├── ApplicativeTests.fs ├── AsyncResultCE.fs ├── Benchmarks.fs ├── Program.fs ├── SeqTests.fs ├── TaskResultCE.fs └── benchmarks.fsproj ├── book.json ├── build.cmd ├── build.sh ├── build ├── DotEnv.fs ├── build.fs └── build.fsproj ├── gitbook ├── README.md ├── SUMMARY.md ├── asyncOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── either.md │ ├── map.md │ ├── orElseFunctions.md │ └── others.md ├── asyncResult │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── check.md │ ├── error.md │ ├── foldResult.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofAsync.md │ ├── ofResult.md │ ├── ofTask.md │ ├── ofTaskAction.md │ ├── operators.md │ ├── others.md │ ├── zip.md │ └── zipError.md ├── asyncResultOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── error.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── ofAsyncOption.md │ ├── ofAsyncResult.md │ ├── ofOption.md │ ├── ofResult.md │ └── operators.md ├── asyncValidation │ ├── apply.md │ ├── ce.md │ ├── error.md │ ├── index.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── mapErrors.md │ ├── ofChoice.md │ ├── ofResult.md │ ├── operators.md │ └── zip.md ├── bindMappings.md ├── cancellableTaskOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── either.md │ ├── map.md │ ├── others.md │ └── zip.md ├── cancellableTaskResult │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── foldResult.md │ ├── ignore.md │ ├── index.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofAsync.md │ ├── operators.md │ └── others.md ├── cancellableTaskValidation │ ├── apply.md │ ├── ce.md │ ├── error.md │ ├── index.md │ ├── map2.md │ ├── map3.md │ ├── ofChoice.md │ ├── ofResult.md │ └── operators.md ├── jobOption │ └── ce.md ├── jobResult │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── error.md │ ├── foldResult.md │ ├── fromTask.md │ ├── fromUnitTask.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofAsync.md │ ├── ofJob.md │ ├── ofResult.md │ ├── operators.md │ └── others.md ├── list │ ├── sequenceAsyncResultA.md │ ├── sequenceAsyncResultM.md │ ├── sequenceResultA.md │ ├── sequenceResultM.md │ ├── sequenceTaskResultA.md │ ├── sequenceTaskResultM.md │ ├── traverseAsyncResultA.md │ ├── traverseAsyncResultM.md │ ├── traverseResultA.md │ ├── traverseResultM.md │ ├── traverseTaskResultA.md │ └── traverseTaskResultM.md ├── option │ ├── bind.md │ ├── bindNull.md │ ├── ce.md │ ├── either.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── ofNull.md │ ├── ofPair.md │ ├── ofResult.md │ ├── ofValueOption.md │ ├── sequenceAsync.md │ ├── sequenceAsyncResult.md │ ├── sequenceOptionM.md │ ├── sequenceResult.md │ ├── sequenceTask.md │ ├── sequenceTaskResult.md │ ├── sequenceVOptionM.md │ ├── teeFunctions.md │ ├── toValueOption.md │ ├── traverseAsync.md │ ├── traverseAsyncResult.md │ ├── traverseOptionM.md │ ├── traverseResult.md │ ├── traverseTask.md │ ├── traverseTaskResult.md │ ├── traverseVOptionM.md │ └── zip.md ├── parallelAsyncResult │ ├── ce.md │ ├── map2.md │ └── map3.md ├── parallelAsyncValidation │ ├── ce.md │ ├── map2.md │ └── map3.md ├── pr.md ├── result │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── check.md │ ├── eitherFunctions.md │ ├── fold.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofChoice.md │ ├── operators.md │ ├── orElseFunctions.md │ ├── others.md │ ├── requireFunctions.md │ ├── teeFunctions.md │ ├── tryCreate.md │ ├── zip.md │ └── zipError.md ├── resultOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofChoice.md │ ├── ofOption.md │ ├── ofResult.md │ ├── operators.md │ ├── zip.md │ └── zipError.md ├── script.fsx ├── seq │ ├── sequenceAsyncResultA.md │ ├── sequenceAsyncResultM.md │ ├── sequenceResultA.md │ ├── sequenceResultM.md │ ├── sequenceTaskResultA.md │ ├── sequenceTaskResultM.md │ ├── traverseAsyncResultA.md │ ├── traverseAsyncResultM.md │ ├── traverseResultA.md │ ├── traverseResultM.md │ ├── traverseTaskResultA.md │ └── traverseTaskResultM.md ├── task │ ├── apply.md │ ├── bind.md │ ├── bindV.md │ ├── catch.md │ ├── ce.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapV.md │ ├── ofUnit.md │ └── zip.md ├── taskOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── either.md │ ├── map.md │ ├── others.md │ └── zip.md ├── taskResult │ ├── apply.md │ ├── bind.md │ ├── catch.md │ ├── ce.md │ ├── check.md │ ├── error.md │ ├── foldResult.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── ofAsync.md │ ├── ofResult.md │ ├── ofTask.md │ ├── operators.md │ ├── others.md │ ├── zip.md │ └── zipError.md ├── taskResultOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── error.md │ ├── ignore.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ └── operators.md ├── taskValidation │ ├── apply.md │ ├── ce.md │ ├── error.md │ ├── index.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── mapErrors.md │ ├── ofChoice.md │ ├── ofResult.md │ ├── operators.md │ └── zip.md ├── taskValueOption │ ├── apply.md │ ├── bind.md │ ├── ce.md │ ├── either.md │ ├── map.md │ ├── others.md │ └── zip.md ├── test │ ├── index.md │ ├── testing-nested1.md │ ├── testing-nested2.md │ └── testing.md └── validation │ ├── apply.md │ ├── ce.md │ ├── error.md │ ├── index.md │ ├── map.md │ ├── map2.md │ ├── map3.md │ ├── mapError.md │ ├── mapErrors.md │ ├── ofChoice.md │ ├── ofResult.md │ ├── operators.md │ └── zip.md ├── global.json ├── msbuild.binlog ├── package-lock.json ├── package.json ├── playground.fsx ├── src ├── Directory.Build.props ├── FsToolkit.ErrorHandling.AsyncSeq │ ├── AssemblyInfo.fs │ ├── FsToolkit.ErrorHandling.AsyncSeq.fsproj │ └── Library.fs ├── FsToolkit.ErrorHandling.IcedTasks │ ├── AssemblyInfo.fs │ ├── CancellableTaskOption.fs │ ├── CancellableTaskOptionBuilderBase.fs │ ├── CancellableTaskOptionCE.fs │ ├── CancellableTaskResultBuilderBase.fs │ ├── CancellableTaskResultCE.fs │ ├── CancellableTaskValidationCE.fs │ ├── CancellableTaskValidationOp.fs │ └── FsToolkit.ErrorHandling.IcedTasks.fsproj ├── FsToolkit.ErrorHandling.JobResult │ ├── AssemblyInfo.fs │ ├── FsToolkit.ErrorHandling.JobResult.fsproj │ ├── Job.fs │ ├── JobOption.fs │ ├── JobOptionCE.fs │ ├── JobOptionOp.fs │ ├── JobResult.fs │ ├── JobResultCE.fs │ ├── JobResultOp.fs │ ├── JobResultOption.fs │ ├── JobResultOptionCE.fs │ ├── JobResultOptionOp.fs │ ├── List.fs │ └── Result.fs └── FsToolkit.ErrorHandling │ ├── Array.fs │ ├── AssemblyInfo.fs │ ├── Async.fs │ ├── AsyncOption.fs │ ├── AsyncOptionCE.fs │ ├── AsyncOptionOp.fs │ ├── AsyncResult.fs │ ├── AsyncResultCE.fs │ ├── AsyncResultOp.fs │ ├── AsyncResultOption.fs │ ├── AsyncResultOptionCE.fs │ ├── AsyncResultOptionOp.fs │ ├── AsyncValidation.fs │ ├── AsyncValidationCE.fs │ ├── AsyncValidationOp.fs │ ├── FsToolkit.ErrorHandling.fsproj │ ├── List.fs │ ├── Nullness.fs │ ├── Option.fs │ ├── OptionCE.fs │ ├── OptionOp.fs │ ├── ParallelAsyncResult.fs │ ├── ParallelAsyncResultCE.fs │ ├── ParallelAsyncValidation.fs │ ├── ParallelAsyncValidationCE.fs │ ├── Result.fs │ ├── ResultCE.fs │ ├── ResultOp.fs │ ├── ResultOption.fs │ ├── ResultOptionCE.fs │ ├── ResultOptionOp.fs │ ├── Script.fsx │ ├── Seq.fs │ ├── Task.fs │ ├── TaskOp.fs │ ├── TaskOption.fs │ ├── TaskOptionCE.fs │ ├── TaskOptionOp.fs │ ├── TaskResult.fs │ ├── TaskResultCE.fs │ ├── TaskResultOp.fs │ ├── TaskResultOption.fs │ ├── TaskResultOptionCE.fs │ ├── TaskResultOptionOp.fs │ ├── TaskValidation.fs │ ├── TaskValidationCE.fs │ ├── TaskValidationOp.fs │ ├── TaskValueOption.fs │ ├── TaskValueOptionCE.fs │ ├── TaskValueOptionOp.fs │ ├── Validation.fs │ ├── ValidationCE.fs │ ├── ValidationOp.fs │ └── ValueOption.fs ├── tests ├── Directory.Build.props ├── FsToolkit.ErrorHandling.AsyncSeq.Tests │ ├── AssemblyInfo.fs │ ├── AsyncSeq.fs │ ├── FsToolkit.ErrorHandling.AsyncSeq.Tests.fsproj │ └── Main.fs ├── FsToolkit.ErrorHandling.IcedTasks.Tests │ ├── AssemblyInfo.fs │ ├── CancellableTaskOptionCE.fs │ ├── CancellableTaskResultCE.fs │ ├── CancellableTaskValidationCE.fs │ ├── Expect.fs │ ├── FsToolkit.ErrorHandling.IcedTasks.Tests.fsproj │ ├── Main.fs │ ├── SampleDomain.fs │ └── TestData.fs ├── FsToolkit.ErrorHandling.JobResult.Tests │ ├── AssemblyInfo.fs │ ├── Expect.JobOption.fs │ ├── Expect.JobResult.fs │ ├── FsToolkit.ErrorHandling.JobResult.Tests.fsproj │ ├── JobOption.fs │ ├── JobOptionCE.fs │ ├── JobResult.fs │ ├── JobResultCE.fs │ ├── JobResultOption.fs │ ├── List.fs │ ├── Main.fs │ └── Result.fs └── FsToolkit.ErrorHandling.Tests │ ├── Array.fs │ ├── AssemblyInfo.fs │ ├── AsyncOption.fs │ ├── AsyncOptionCE.fs │ ├── AsyncResult.fs │ ├── AsyncResultCE.fs │ ├── AsyncResultOption.fs │ ├── AsyncResultOptionCE.fs │ ├── AsyncValidation.fs │ ├── AsyncValidationCE.fs │ ├── BackgroundTaskOptionCE.fs │ ├── BackgroundTaskResultCE.fs │ ├── BackgroundTaskValueOptionCE.fs │ ├── Expect.fs │ ├── Expecto.fs │ ├── FsToolkit.ErrorHandling.Tests.fsproj │ ├── List.fs │ ├── Main.fs │ ├── Option.fs │ ├── OptionCE.fs │ ├── ParallelAsyncResult.fs │ ├── ParallelAsyncResultCE.fs │ ├── ParallelAsyncValidation.fs │ ├── ParallelAsyncValidationCE.fs │ ├── Result.fs │ ├── ResultCE.fs │ ├── ResultOption.fs │ ├── ResultOptionCE.fs │ ├── SampleDomain.fs │ ├── Seq.fs │ ├── TaskOption.fs │ ├── TaskOptionCE.fs │ ├── TaskResult.fs │ ├── TaskResultCE.fs │ ├── TaskResultOption.fs │ ├── TaskValidation.fs │ ├── TaskValidationCE.fs │ ├── TaskValueOption.fs │ ├── TaskValueOptionCE.fs │ ├── TestData.fs │ ├── TestHelpers.fs │ ├── Validation.fs │ ├── ValidationCE.fs │ ├── ValueOption.fs │ ├── ValueOptionCE.fs │ └── my-file.csv └── tools └── FunctionMap ├── FunctionMap.fsproj ├── Program.fs └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } -------------------------------------------------------------------------------- /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "fable": { 6 | "version": "4.25.0", 7 | "commands": [ 8 | "fable" 9 | ], 10 | "rollForward": false 11 | }, 12 | "fantomas": { 13 | "version": "7.0.2", 14 | "commands": [ 15 | "fantomas" 16 | ], 17 | "rollForward": false 18 | }, 19 | "femto": { 20 | "version": "0.21.0", 21 | "commands": [ 22 | "femto" 23 | ], 24 | "rollForward": false 25 | }, 26 | "fsharp-analyzers": { 27 | "version": "0.31.0", 28 | "commands": [ 29 | "fsharp-analyzers" 30 | ], 31 | "rollForward": false 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # [Choice] Debian version (use bullseye on local arm64/Apple Silicon): bookworm, bullseye, buster 2 | ARG VARIANT="bookworm" 3 | FROM buildpack-deps:${VARIANT}-curl 4 | 5 | 6 | ENV \ 7 | # Enable detection of running in a container 8 | DOTNET_RUNNING_IN_CONTAINER=true \ 9 | DOTNET_ROOT=/usr/share/dotnet/ \ 10 | DOTNET_NOLOGO=true \ 11 | DOTNET_CLI_TELEMETRY_OPTOUT=false 12 | 13 | 14 | # [Optional] Uncomment this section to install additional OS packages. 15 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 16 | # && apt-get -y install --no-install-recommends 17 | -------------------------------------------------------------------------------- /.fantomasignore: -------------------------------------------------------------------------------- 1 | AssemblyInfo.fs 2 | tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/Main.fs 3 | tests/FsToolkit.ErrorHandling.Tests/Main.fs -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # This file contains a list of git hashes of revisions to be ignored by git 2 | # These revisions are considered "unimportant" in 3 | # that they are unlikely to be what you are interested in when blaming. 4 | # Like formatting with Fantomas 5 | # https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view 6 | 7 | # Add formatting commits here 8 | 9 | b49d1e213eb4c0bd4019205e4364cb5681b5286b 10 | b056b98c6e588f0cfdbe872d55aa660cefbb1ef9 11 | 0c7b80a4f45e241225fd7c73b5611b0054726d69 12 | 929208c7cbd0cb25234f8539e98c4ae6dda08a28 13 | 7d550115f883a4974d034f56429fb381137b2ff1 14 | 6443fcd54234f21bc991a176be3487d47177b3e6 15 | 12826147dac65cd640ef265379f9f7bfdcff725b 16 | 94e54b935777be332f7eed5b0bd6a39f379223af 17 | 8fe525c788b7cdca77dbcf73b3db437d20560a61 18 | b49d1e213eb4c0bd4019205e4364cb5681b5286b 19 | fb350c3b58edc8dfb8917f1a1e32962fe18d42f9 20 | 05904c2243baad57965bfebfcde0113e22f74c64 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp text=auto eol=lf 6 | *.vb diff=csharp text=auto eol=lf 7 | *.fs diff=csharp text=auto eol=lf 8 | *.fsi diff=csharp text=auto eol=lf 9 | *.fsx diff=csharp text=auto eol=lf 10 | *.sln text eol=crlf merge=union 11 | *.csproj merge=union 12 | *.vbproj merge=union 13 | *.fsproj merge=union 14 | *.dbproj merge=union 15 | *.sh text eol=lf 16 | 17 | # Standard to msysgit 18 | *.doc diff=astextplain 19 | *.DOC diff=astextplain 20 | *.docx diff=astextplain 21 | *.DOCX diff=astextplain 22 | *.dot diff=astextplain 23 | *.DOT diff=astextplain 24 | *.pdf diff=astextplain 25 | *.PDF diff=astextplain 26 | *.rtf diff=astextplain 27 | *.RTF diff=astextplain 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | Please insert a description of your problem or question. 4 | 5 | ## Error messages, screenshots 6 | 7 | Please add any error logs or screenshots if available. 8 | 9 | ## Failing test, failing GitHub repo, or reproduction steps 10 | 11 | Please add either a failing test, a GitHub repo of the problem or detailed reproduction steps. 12 | 13 | ## Expected Behavior 14 | 15 | Please define what you would expect the behavior to be like. 16 | 17 | ## Known workarounds 18 | 19 | Please provide a description of any known workarounds. 20 | 21 | ## Other information 22 | 23 | * Operating System: 24 | - [ ] windows [insert version here] 25 | - [ ] macOs [insert version] 26 | - [ ] linux [insert flavor/version here] 27 | * Platform 28 | - [ ] dotnet core 29 | - [ ] dotnet full 30 | - [ ] mono 31 | * Branch or release version: -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Desktop (please complete the following information):** 24 | - OS: [e.g. iOS] 25 | - Browser [e.g. chrome, safari] 26 | - Version [e.g. 22] 27 | 28 | **Smartphone (please complete the following information):** 29 | - Device: [e.g. iPhone6] 30 | - OS: [e.g. iOS8.1] 31 | - Browser [e.g. stock browser, safari] 32 | - Version [e.g. 22] 33 | 34 | **Additional context** 35 | Add any other context about the problem here. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 16.0.0 2 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ionide.ionide-fsharp", 4 | "ionide.ionide-fake", 5 | "ms-dotnettools.csharp", 6 | "editorConfig.editorConfig", 7 | "ms-vscode-remote.remote-containers", 8 | "usernamehw.errorlens", 9 | "oderwat.indent-rainbow", 10 | "tintoy.msbuild-project-tools", 11 | "2gua.rainbow-brackets" 12 | 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "benchmarks", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "program": "${workspaceFolder}/benchmarks/bin/Release/net8.0/benchmarks.exe", 9 | "args": ["-m", "--runtimes", "net8.0", "--filter", "*"], 10 | "env": { 11 | "ASPNETCORE_ENVIRONMENT": "Development" 12 | }, 13 | "console": "integratedTerminal", 14 | "preLaunchTask": "build release", 15 | "cwd": "${workspaceFolder}/benchmarks/bin/Release/net8.0/" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.inlayHints.enabled": "off", 3 | "FSharp.enableMSBuildProjectGraph": true, 4 | "[fsharp]": { 5 | "editor.formatOnSave": true, 6 | }, 7 | "FSharp.notifications.trace": false, 8 | "FSharp.notifications.traceNamespaces": [ 9 | "BoundModel.TypeCheck", 10 | "BackgroundCompiler." 11 | ], 12 | "FSharp.fsac.parallelReferenceResolution": false, 13 | "FSharp.enableAnalyzers": true, 14 | "FSharp.analyzersPath": [ 15 | "packages/analyzers" 16 | ] 17 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build release", 6 | "type": "process", 7 | "command": "dotnet", 8 | "args": [ 9 | "build", 10 | "-c", 11 | "Release", 12 | "${workspaceFolder}/FsToolkit.ErrorHandling.sln", 13 | "/property:GenerateFullPaths=true", 14 | "/consoleloggerparameters:NoSummary" 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /Ajira-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demystifyfp/FsToolkit.ErrorHandling/47f197db5940fc56ca90cab29afd6801aa09d7c1/Ajira-logo.png -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | $(NoWarn);FS2003;NU1903;NU1904;FS0057 5 | true 6 | 7 | 13 | 8.0 14 | 9.0 15 | enable 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Directory.Solution.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | <_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/ 4 | <_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json 5 | <_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 DemystifyFP 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /benchmarks/Program.fs: -------------------------------------------------------------------------------- 1 | open BenchmarkDotNet.Running 2 | open BenchmarkDotNet.Configs 3 | open BenchmarkDotNet.Columns 4 | open BenchmarkDotNet.Reports 5 | open System.Reflection 6 | 7 | 8 | [] 9 | let main argv = 10 | 11 | let cfg = 12 | DefaultConfig.Instance 13 | .AddColumn(StatisticColumn.P80, StatisticColumn.P95) 14 | .WithSummaryStyle(SummaryStyle.Default.WithRatioStyle(RatioStyle.Trend)) 15 | 16 | // see here for console args: https://benchmarkdotnet.org/articles/guides/console-args.html 17 | BenchmarkRunner.Run(assembly = Assembly.GetExecutingAssembly(), config = cfg, args = argv) 18 | |> ignore 19 | 20 | 0 // return an integer exit code 21 | -------------------------------------------------------------------------------- /benchmarks/benchmarks.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0;net9.0 5 | Exe 6 | 7 | 8 | AnyCPU 9 | true 10 | true 11 | true 12 | Release 13 | false 14 | FS1204;FS3501;FS3511 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /book.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": "./gitbook" 3 | } -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | echo Restoring dotnet tools... 2 | dotnet tool restore 3 | 4 | dotnet run --project ./build/build.fsproj -- -t %* -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # -*- coding: utf-8 -*- 3 | 4 | set -eu 5 | set -o pipefail 6 | 7 | echo "Restoring dotnet tools..." 8 | dotnet tool restore 9 | 10 | FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@" 11 | -------------------------------------------------------------------------------- /build/DotEnv.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.Build 2 | 3 | module DotEnv = 4 | open Fake.Core 5 | open System 6 | open System.IO 7 | 8 | let private parseLine (line: string) = 9 | match line.Split('=', StringSplitOptions.RemoveEmptyEntries) with 10 | | args when args.Length = 2 -> Environment.SetEnvironmentVariable(args.[0], args.[1]) 11 | | _ -> () 12 | 13 | let load (rootDir) = 14 | let filePath = Path.Combine(rootDir, ".env") 15 | 16 | if File.Exists filePath then 17 | filePath 18 | |> File.ReadAllLines 19 | |> Seq.iter parseLine 20 | else 21 | Trace.traceImportantfn "No .env file found. %s" rootDir 22 | -------------------------------------------------------------------------------- /build/build.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /gitbook/asyncOption/apply.md: -------------------------------------------------------------------------------- 1 | # AsyncOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async<('a -> 'b) option> -> Async<'a option> 9 | -> Async<'b option> 10 | ``` 11 | 12 | ## Examples 13 | 14 | Take the following function for example 15 | 16 | ```fsharp 17 | // string -> int 18 | let characterCount (s: string) = s.Length 19 | ``` 20 | 21 | ### Example 1 22 | 23 | ```fsharp 24 | let result = 25 | AsyncOption.some "foo" // Async 26 | |> AsyncOption.apply (AsyncOption.some characterCount) // Async 27 | 28 | // async { Some 3 } 29 | ``` 30 | 31 | ### Example 2 32 | 33 | ```fsharp 34 | let result = 35 | Async.singleton None // Async 36 | |> AsyncOption.apply (AsyncOption.some characterCount) // Async 37 | 38 | // async { None } 39 | ``` 40 | 41 | ### Example 3 42 | 43 | ```fsharp 44 | let result : Async = 45 | AsyncOption.some "foo" // Async 46 | |> AsyncOption.apply (Async.singleton None) // Async 47 | 48 | // async { None } 49 | ``` 50 | -------------------------------------------------------------------------------- /gitbook/asyncOption/ce.md: -------------------------------------------------------------------------------- 1 | ## AsyncOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | tryParseInt : string -> Option 13 | tryFindPersonById : int -> Async> 14 | updatePerson : Person -> Async 15 | ``` 16 | 17 | ```fsharp 18 | // Async> 19 | let addResult = asyncOption { 20 | let! personId = tryParseInt "3001" 21 | let! age = tryParseInt "35" 22 | let! person = tryFindPersonById personId "US-OH" 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` -------------------------------------------------------------------------------- /gitbook/asyncOption/either.md: -------------------------------------------------------------------------------- 1 | # AsyncOption.either 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | Provide two functions to execute depending on the value of the option. If the option is `Some`, the first function will be executed. If the option is `None`, the second function will be executed. 8 | 9 | ```fsharp 10 | (onSome : 'T -> Async<'output>) -> (onNone : Async<'output>) -> (input : Async<'T option>) -> Async<'output> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | AsyncOption.either (fun x -> async { x * 2 }) (async { 0 }) (AsyncOption.some 5) 19 | 20 | // async { 10 } 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | AsyncOption.either (fun x -> x * 2) (async { 0 }) None 27 | 28 | // async { 0 } 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/asyncOption/map.md: -------------------------------------------------------------------------------- 1 | # AsyncOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of an async option if it is `Some`. If the option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('TInput -> 'TOutput) -> Async<'TInput option> -> Async<'TOutput option> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | AsyncOption.map (fun x -> x + 1) (AsyncOption.some 1) 19 | 20 | // async { Some 2 } 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | AsyncOption.map (fun x -> x + 1) (Async.singleton None) 27 | 28 | // async { None } 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/asyncOption/others.md: -------------------------------------------------------------------------------- 1 | # Other AsyncOption Functions 2 | 3 | ## defaultValue 4 | 5 | Returns the contained value if Some, otherwise returns the provided value 6 | 7 | ### Function Signature 8 | 9 | ```fsharp 10 | 'a -> Async<'a option> -> Async<'a> 11 | ``` 12 | 13 | ## defaultWith 14 | 15 | Returns the contained value if Some, otherwise evaluates the given function and returns the result. 16 | 17 | ### Function Signature 18 | 19 | ```fsharp 20 | (unit -> 'a) -> Async<'a option> -> Async<'a> 21 | ``` 22 | 23 | ## some 24 | 25 | Wraps the provided value in an Async 26 | 27 | ### Function Signature 28 | 29 | ```fsharp 30 | 'a -> Async<'a option> 31 | ``` 32 | 33 | 34 | -------------------------------------------------------------------------------- /gitbook/asyncResult/apply.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async 'b), 'c>> 9 | -> Async> 10 | -> Async> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/asyncResult/bind.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Async>) 9 | -> Async> 10 | -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` operations can also be solved using [the `asyncResult` computation expression](../asyncResult/ce.md). 16 | 17 | ### Example 1 18 | 19 | Continuing from the [AsyncResult.map2 example](../asyncResult/map2.md#example-1) and given the function 20 | 21 | ```fsharp 22 | let notifyFollowers : NotifyNewPostRequest -> Async> 23 | ``` 24 | 25 | we can notify all followers using `AsyncResult.bind` as below: 26 | 27 | ```fsharp 28 | newPostRequestResult |> AsyncResult.bind notifyFollowers 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ce.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | 6 | ## Examples 7 | 8 | ### Example 1 9 | 10 | The initial [motivating example](../../) is perhaps more realistic if some functions are asynchronous. Given the following functions: 11 | 12 | ```fsharp 13 | tryGetUser : string -> Async 14 | isPwdValid : string -> User -> bool 15 | authorize : User -> Async> 16 | createAuthToken : User -> Result 17 | ``` 18 | 19 | A login flow can be implemented as below using the `asyncResult` CE and a few [helpers](others.md): 20 | 21 | ```fsharp 22 | type LoginError = 23 | | InvalidUser 24 | | InvalidPwd 25 | | Unauthorized of AuthError 26 | | TokenErr of TokenError 27 | 28 | let login (username: string) (password: string) : Async> = 29 | asyncResult { 30 | let! user = username |> tryGetUser |> AsyncResult.requireSome InvalidUser 31 | do! user |> isPwdValid password |> Result.requireTrue InvalidPwd 32 | do! user |> authorize |> AsyncResult.mapError Unauthorized 33 | return! user |> createAuthToken |> Result.mapError TokenErr 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /gitbook/asyncResult/error.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Async>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Async> = 20 | AsyncResult.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/asyncResult/foldResult.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.foldResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> ('c -> 'b) -> Async> -> Async<'b> 9 | ``` 10 | 11 | This is just a shortcut for `Async.map Result.fold`. See [Result.fold](../result/fold.md) for more. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | type HttpResponse<'a, 'b> = 19 | | Ok of 'a 20 | | InternalError of 'b 21 | 22 | // CreatePostRequest -> Async> 23 | let createPost (req : CreatePostRequest) = async { 24 | // ... 25 | } 26 | 27 | // Async 28 | let handler (httpReq : HttpRequest) = 29 | // ... 30 | 31 | // Async> 32 | let createPostAR = createPost httpReq 33 | 34 | createPostAR 35 | |> AsyncResult.fold Ok InternalError 36 | ``` 37 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ignore.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async> -> Async> 9 | ``` 10 | 11 | This is a shortcut for `AsyncResult.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> Async> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `AsyncResult.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = asyncResult { 25 | do! savePost createPostRequest |> AsyncResult.ignore 26 | } 27 | ``` -------------------------------------------------------------------------------- /gitbook/asyncResult/map.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Async> -> Async> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `map` operations can also be solved using [the `asyncResult` computation expression](../asyncResult/ce.md). 14 | 15 | ### Example 1 16 | 17 | As a continuation of [Result.map3 Example 2](../result/map3.md#example-2), let's assume that we want to store the created post in the database using the function 18 | 19 | ```fsharp 20 | savePost : CreatePostRequest -> Async> 21 | ``` 22 | 23 | We can save the post and return its inner using `AsyncResult.map`: 24 | 25 | ```fsharp 26 | let rawPostId : Async> = 27 | savePost createPostRequest 28 | |> AsyncResult.map (fun (PostId postId) -> postId) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/asyncResult/map3.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | -> Async> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `asyncResult` computation expression](../asyncResult/ce.md). -------------------------------------------------------------------------------- /gitbook/asyncResult/mapError.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Async> -> Async> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | From the [AsyncResult.map](../asyncResult/map.md#example-1) example, if we want to map the error part alone, we can do it as below: 16 | 17 | ```fsharp 18 | // Async, string> 19 | createPost createPostRequest 20 | |> AsyncResult.mapError (fun (ex : exn) -> ex.Message) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ofAsync.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.ofAsync 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Async<'T>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Async<'T> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResult.ofAsync (async { return 42 }) 19 | // async { return Ok 42 } 20 | ``` 21 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ofResult.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResult.ofResult (Ok 42) 19 | // async { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResult.ofResult (Error "Boom!") 26 | // async { return Error "Boom!" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ofTask.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.ofTask 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task<'T>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'T> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResult.ofTask (Task.FromResult 42) 19 | // async { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResult.ofTask (Task.FromException (System.Exception("Boom!"))) 26 | // async { return Error (System.Exception("Boom!")) } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResult/ofTaskAction.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.ofTaskAction 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResult.ofTaskAction (Task.Delay 1000) 19 | // async { do () } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResult.ofTaskAction (Task.FromException (System.Exception("Boom!"))) 26 | // async { return Error (System.Exception("Boom!")) } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResult/operators.md: -------------------------------------------------------------------------------- 1 | ## AsyncResult Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.AsyncResult` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `Async>` type. 6 | 7 | ## Examples: 8 | 9 | ### Example 1 10 | 11 | Expanding on the [AsyncResult.map2 example](../asyncResult/map2.md#example-1), we define another function: 12 | 13 | ```fsharp 14 | notifyFollowers : NotifyNewPostRequest -> Async> 15 | ``` 16 | 17 | We can then rewrite the example and additionally call `notifyFollowers` using the operators as below: 18 | 19 | ```fsharp 20 | open FsToolkit.ErrorHandling.Operator.AsyncResult 21 | 22 | // CreatePostRequest -> Async> 23 | let createPostAndNotifyFollowers (req : CreatePostRequest) = 24 | notifyNewPostRequest 25 | (getFollowerIds req.UserId) 26 | <*> (createPost req) 27 | >>= notifyFollowers 28 | ``` 29 | -------------------------------------------------------------------------------- /gitbook/asyncResult/zip.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Async> -> Async> -> Async> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = AsyncResult.zip (AsyncResult.ok 1) (AsyncResult.ok 2) 17 | // async { Ok (1, 2) } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = AsyncResult.zip (AsyncResult.ok 1) (AsyncResult.error "Bad") 24 | // async { Error "Bad" } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = AsyncResult.zip (AsyncResult.error "Bad1") (AsyncResult.error "Bad2") 31 | // async { Error "Bad1" } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/asyncResult/zipError.md: -------------------------------------------------------------------------------- 1 | # AsyncResult.zipError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Async> -> Async> -> Async> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = AsyncResult.zipError (AsyncResult.ok 1) (AsyncResult.ok 2) 17 | // async { Ok 1 } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = AsyncResult.zipError (AsyncResult.ok 1) (AsyncResult.error "Bad") 24 | // async { Ok 1 } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = AsyncResult.zipError (AsyncResult.error "Bad1") (AsyncResult.error "Bad2") 31 | // async { Error("Bad1", "Bad2") } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/apply.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async 'b) option, 'c>> 9 | -> Async> 10 | -> Async> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/bind.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Async>) 9 | -> Async> 10 | -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` can also be solved using [the `asyncResultOption` computation expression](ce.md). 16 | 17 | ### Example 1 18 | 19 | Given the following functions: 20 | 21 | ```fsharp 22 | getUserById : UserId -> Async> 23 | getPostById : PostId -> Async> 24 | ``` 25 | 26 | We can get a post's user given a `PostId` like this: 27 | 28 | ```fsharp 29 | // Async> 30 | getPostById postId 31 | |> AsyncResultOption.bind (fun post -> getUserById post.UserId) 32 | ``` -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ce.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | 6 | ## Examples 7 | 8 | ### Example 1 9 | 10 | The [AsyncResultOption.map2 example](../asyncResultOption/map2.md#example-1) can be written using the `asyncResultOption` computation expression as below: 11 | 12 | ```fsharp 13 | // Async> 14 | asyncResultOption { 15 | let! post = getPostById samplePostId 16 | let! user = getUserById post.UserId 17 | return userTweet post user 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/error.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Async>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Async> = 20 | AsyncResultOption.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ignore.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async> -> Async> 9 | ``` 10 | 11 | This is a shortcut for `AsyncResultOption.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let deletePostIfExists : DeletePostRequest -> Async> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `AsyncResultOption.ignore` as below: 22 | 23 | ```fsharp 24 | let deletePost = asyncResultOption { 25 | do! deletePostIfExists deletePostRequest |> AsyncResultOption.ignore 26 | } 27 | ``` -------------------------------------------------------------------------------- /gitbook/asyncResultOption/map.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Async> 9 | -> Async> 10 | ``` 11 | 12 | ## Examples 13 | 14 | Note: Many use-cases requiring `map` operations can also be solved using [the `asyncResultOption` computation expression](ce.md). 15 | 16 | ### Example 1 17 | 18 | Given the function 19 | 20 | ```fsharp 21 | getUserById : UserId -> Async> 22 | ``` 23 | 24 | Then using the `AsyncResultOption.map` we can get the name of the user like this: 25 | 26 | ```fsharp 27 | // Async, exn> 28 | getUserById sampleUserId 29 | |> AsyncResultOption.map (fun user -> user.Name) 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/map2.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Note: Many use-cases requiring `map` operations can also be solved using [the `asyncResultOption` computation expression](ce.md). 17 | 18 | ### Example 1 19 | 20 | Given the following functions: 21 | 22 | ```fsharp 23 | getPostById : PostId -> Async> 24 | getUserById : UserId -> Async> 25 | userTweet : Post -> User -> UserTweet 26 | ``` 27 | 28 | Then given a `PostId` and a `UserId`, we can call `userTweet` like this: 29 | 30 | ```fsharp 31 | // Async> 32 | AsyncResultOption.map2 userTweet (getPostById postId) (getUserById userId) 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/map3.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | -> Async> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `asyncResultOption` computation expression](ce.md). -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ofAsyncOption.md: -------------------------------------------------------------------------------- 1 | # AsyncResultOption.ofAsyncOption 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Async<'T option>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Async<'T option> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResultOption.ofAsyncOption (async { return Some 42 }) 19 | // async { return Ok (Some 42) } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResultOption.ofAsyncOption (async { return None }) 26 | // async { return Ok None } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ofAsyncResult.md: -------------------------------------------------------------------------------- 1 | # AsyncResultOption.ofAsyncResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Async>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Async> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResultOption.ofAsyncResult (async { return Ok 42 }) 19 | // async { return Ok (Some 42) } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResultOption.ofAsyncResult (async { return Error "error" }) 26 | // async { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ofOption.md: -------------------------------------------------------------------------------- 1 | # AsyncResultOption.ofOption 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `'T option` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'T option -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResultOption.ofOption (Some 42) 19 | // async { return Ok (Some 42) } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResultOption.ofOption None 26 | // async { return Ok None } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/ofResult.md: -------------------------------------------------------------------------------- 1 | # AsyncResultOption.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into an `Async>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncResultOption.ofResult (Ok 42) 19 | // async { return Ok (Some 42) } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncResultOption.ofResult (Error "error") 26 | // async { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncResultOption/operators.md: -------------------------------------------------------------------------------- 1 | ## AsyncResultOption Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.AsyncResultOption` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `Result,_>` type. 6 | 7 | ## Examples 8 | 9 | ### Example 1 10 | 11 | The [AsyncResultOption map2 example](../asyncResultOption/map2.md#example-1) can be written using operators like this: 12 | 13 | ```fsharp 14 | open FsToolkit.ErrorHandling.Operator.AsyncResult 15 | 16 | // Async> 17 | userTweet 18 | (getPostById samplePostId) 19 | <*> (getUserById sampleUserId) 20 | ``` 21 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/apply.md: -------------------------------------------------------------------------------- 1 | ## AsyncValidation.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async 'b), 'c list>> 9 | -> Async> 10 | -> Async> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/ce.md: -------------------------------------------------------------------------------- 1 | ## AsyncValidation Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | The `AsyncValidation` type is defined as: 6 | 7 | ```fsharp 8 | type AsyncValidation<'a,'err> = Async> 9 | ``` 10 | 11 | This CE can take advantage of the [and! operator](https://github.com/fsharp/fslang-suggestions/issues/579) to join multiple error results into a list. 12 | 13 | ## Examples 14 | 15 | See [here](../validation/ce.md) for other validation-like examples 16 | 17 | ```fsharp 18 | // Result -> Async> 19 | let downloadAsync stuff = async { 20 | return stuff 21 | } 22 | 23 | // AsyncValidation 24 | let addResult = asyncValidation { 25 | let! x = downloadAsync (Ok "I") 26 | and! y = downloadAsync (Ok "am") 27 | and! z = downloadAsync (Ok "async!") 28 | return sprintf "%s %s %s" x y z 29 | } 30 | // async { return Ok "I am async!" } 31 | 32 | // AsyncValidation 33 | let addResult = asyncValidation { 34 | let! x = downloadAsync (Error "Am") 35 | and! y = downloadAsync (Error "I") 36 | and! z = downloadAsync (Error "async?") 37 | return sprintf "%s %s %s" x y z 38 | } 39 | 40 | // async { return Error [ "Am"; "I"; "async?" ] } 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/error.md: -------------------------------------------------------------------------------- 1 | ## AsyncValidation.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Async>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Async> = 20 | AsyncValidation.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/index.md: -------------------------------------------------------------------------------- 1 | # AsyncValidation 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This module provides utility functions and infix operators to work with `Async>`. 6 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/map2.md: -------------------------------------------------------------------------------- 1 | ## AsyncValidation.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | ``` 13 | 14 | Like [Result.map2](../result/map2.md), but collects the errors from both arguments. 15 | 16 | ## Examples 17 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/map3.md: -------------------------------------------------------------------------------- 1 | ## AsyncValidation.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | -> Async> 13 | ``` 14 | 15 | Like [Result.map3](../result/map3.md), but collects the errors from all arguments. 16 | 17 | ## Examples 18 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/mapError.md: -------------------------------------------------------------------------------- 1 | # AsyncValidation.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `mapError` takes an async validation and a normal function and returns a new async validation value based on the input error value and the function 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput -> 'errorOutput) -> AsyncValidation<'ok, 'errorInput> 11 | -> AsyncValidation<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (message: string) = 21 | match message with 22 | | "bad things happened" -> 1 23 | | _ -> 0 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | AsyncValidation.ok "all good" // AsyncValidation 31 | |> AsyncValidation.mapError getErrorCode // AsyncValidation 32 | 33 | // async { Ok "all good" } 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result = 40 | AsyncValidation.error "bad things happened" // AsyncValidation 41 | |> AsyncValidation.mapError getErrorCode // AsyncValidation 42 | 43 | // async { Error [1] } 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/ofChoice.md: -------------------------------------------------------------------------------- 1 | # AsyncValidation.ofChoice 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Choice<'T, 'Error>` into a `Async>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'T, 'Error> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncValidation.ofChoice (Choice1Of2 42) 19 | // async { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncValidation.ofChoice (Choice2Of2 "error") 26 | // async { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/ofResult.md: -------------------------------------------------------------------------------- 1 | # AsyncValidation.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into a `Async>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Async> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = AsyncValidation.ofResult (Ok 42) 19 | // async { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = AsyncValidation.ofResult (Error "error") 26 | // async { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/asyncValidation/zip.md: -------------------------------------------------------------------------------- 1 | # AsyncValidation.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | AsyncValidation<'leftOk, 'error> -> AsyncValidation<'rightOk, 'error> -> AsyncValidation<'leftOk * 'rightOk, 'error> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = AsyncValidation.zip (AsyncValidation.ok 1) (AsyncValidation.ok 2) 17 | // async { Ok (1, 2) } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = AsyncValidation.zip (AsyncValidation.ok 1) (AsyncValidation.error "Bad") 24 | // async { Error [ "Bad" ] } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = AsyncValidation.zip (AsyncValidation.error "Bad1") (AsyncValidation.error "Bad2") 31 | // async { Error [ "Bad1"; "Bad2" ] } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskOption/ce.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | tryParseInt : string -> Option 13 | tryFindPersonById : int -> CancellableTask 14 | updatePerson : Person -> CancellableTask 15 | ``` 16 | 17 | ```fsharp 18 | // CancellableTask 19 | let addResult = cancellableTaskOption { 20 | let! personId = tryParseInt "3001" 21 | let! age = tryParseInt "35" 22 | let! person = tryFindPersonById personId 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskOption/either.md: -------------------------------------------------------------------------------- 1 | # CancellableTaskOption.either 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | Provide two functions to execute depending on the value of the option. If the option is `Some`, the first function will be executed. If the option is `None`, the second function will be executed. 8 | 9 | ```fsharp 10 | (onSome : 'T -> CancellableTask<'output>) 11 | -> (onNone : CancellableTask<'output>) 12 | -> (input : CancellableTask<'T option>) 13 | -> CancellableTask<'output> 14 | ``` 15 | 16 | ## Examples 17 | 18 | ### Example 1 19 | 20 | ```fsharp 21 | CancellableTaskOption.either (fun x -> cancellableTask { x * 2 }) (cancellableTask { 0 }) (CancellableTaskOption.some 5) 22 | 23 | // cancellableTask { 10 } 24 | ``` 25 | 26 | ### Example 2 27 | 28 | ```fsharp 29 | CancellableTaskOption.either (fun x -> x * 2) (cancellableTask { 0 }) None 30 | 31 | // cancellableTask { 0 } 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskOption/map.md: -------------------------------------------------------------------------------- 1 | # CancellableTaskOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of a cancellable task option if it is `Some`. If the option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('input -> 'output) -> CancellableTask<'input option> -> CancellableTask<'output option> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | CancellableTaskOption.map (fun x -> x + 1) (CancellableTaskOption.some 1) 19 | 20 | // cancellableTask { Some 2 } 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | CancellableTaskOption.map (fun x -> x + 1) (CancellableTask.singleton None) 27 | 28 | // cancellableTask { None } 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskOption/others.md: -------------------------------------------------------------------------------- 1 | # Other CancellableTaskOption Functions 2 | 3 | ## defaultValue 4 | 5 | Returns the contained value if Some, otherwise returns the provided value 6 | 7 | ### Function Signature 8 | 9 | ```fsharp 10 | 'a -> CancellableTask<'a option> -> CancellableTask<'a> 11 | ``` 12 | 13 | ## defaultWith 14 | 15 | Returns the contained value if Some, otherwise evaluates the given function and returns the result. 16 | 17 | ### Function Signature 18 | 19 | ```fsharp 20 | (unit -> 'a) -> CancellableTask<'a option> -> CancellableTask<'a> 21 | ``` 22 | 23 | ## some 24 | 25 | Wraps the provided value in an CancellableTask<'a option> 26 | 27 | ### Function Signature 28 | 29 | ```fsharp 30 | 'a -> CancellableTask<'a option> 31 | ``` 32 | 33 | 34 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskOption/zip.md: -------------------------------------------------------------------------------- 1 | # CancellableTaskOption.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Takes two options and returns a tuple of the pair or None if either are None 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | CancellableTask<'left option> -> CancellableTask<'right option> -> CancellableTask<('left * 'right) option> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let left = CancellableTaskOption.some 123 19 | let right = CancellableTaskOption.some "abc" 20 | 21 | CancellableTaskOption.zip left right 22 | // cancellableTask { Some (123, "abc") } 23 | ``` 24 | 25 | ### Example 2 26 | 27 | ```fsharp 28 | let left = CancellableTaskOption.some 123 29 | let right = CancellableTaskOption.singleton None 30 | 31 | CancellableTaskOption.zip left right 32 | // cancellableTask { None } 33 | ``` 34 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/apply.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | CancellableTask 'b), 'c>> 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/bind.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> CancellableTask>) 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` operations can also be solved using [the `cancellableTaskResult` computation expression](../cancellableTaskResult/ce.md). 16 | 17 | ### Example 1 18 | 19 | Continuing from the [CancellableTaskResult.map2 example](../cancellableTaskResult/map2.md#example-1) and given the function 20 | 21 | ```fsharp 22 | let notifyFollowers : NotifyNewPostRequest -> CancellableTask> 23 | ``` 24 | 25 | We can notify all followers using `CancellableTaskResult.bind` as below: 26 | 27 | ```fsharp 28 | newPostRequestResult |> CancellableTaskResult.bind notifyFollowers 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/foldResult.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.foldResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> ('c -> 'b) -> CancellableTask> -> Task<'b> 9 | ``` 10 | 11 | This is just a shortcut for `Task.map Result.fold`. See [Result.fold](../result/fold.md) for more. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | type HttpResponse<'a, 'b> = 19 | | Ok of 'a 20 | | InternalError of 'b 21 | 22 | // CreatePostRequest -> CancellableTask> 23 | let createPost (req : CreatePostRequest) = cancellableTask { 24 | // ... 25 | } 26 | 27 | // CancellableTask 28 | let handler (httpReq : HttpRequest) = 29 | // ... 30 | 31 | // CancellableTask> 32 | let createPostTR = createPost httpReq 33 | 34 | createPostTR 35 | |> CancellableTaskResult.fold Ok InternalError 36 | ``` 37 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/ignore.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | CancellableTask> -> CancellableTask> 9 | ``` 10 | 11 | This is a shortcut for `CancellableTaskResult.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> CancellableTask> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `CancellableTaskResult.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = cancellableTaskResult { 25 | do! savePost createPostRequest |> CancellableTaskResult.ignore 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/index.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This module provides utility functions and infix operators to work with `CancellableTask>`. 6 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/map.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> CancellableTask> -> CancellableTask> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `map` operations can also be solved using [the `cancellableTaskResult` computation expression](../cancellableTaskResult/ce.md). 14 | 15 | ### Example 1 16 | 17 | As a continuation of [Result.map3 Example 2](../result/map3.md#example-2), let's assume that we want to store the created post in the database using the function 18 | 19 | ```fsharp 20 | savePost : CreatePostRequest -> CancellableTask> 21 | ``` 22 | 23 | We can save the post and return its inner using `CancellableTaskResult.map`: 24 | 25 | ```fsharp 26 | let rawPostId : CancellableTask> = 27 | savePost createPostRequest 28 | |> CancellableTaskResult.map (fun (PostId postId) -> postId) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/map3.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | -> CancellableTask> 12 | -> CancellableTask> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `cancellableTaskResult` computation expression](../cancellableTaskResult/ce.md). 18 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/mapError.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> CancellableTask> -> CancellableTask> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | From the [CancellableTaskResult.map](../cancellableTaskResult/map.md#example-1) example, if we want to map the error part alone, we can do it as below: 16 | 17 | ```fsharp 18 | // CancellableTask, string> 19 | createPost createPostRequest 20 | |> CancellableTaskResult.mapError (fun (ex : exn) -> ex.Message) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/ofAsync.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult.ofAsync 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async<'a> -> CancellableTask> 9 | ``` 10 | 11 | ## Examples 12 | 13 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskResult/operators.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskResult Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.CancellableTaskResult` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `CancellableTask>` type. 6 | 7 | ## Examples: 8 | 9 | ### Example 1 10 | 11 | Expanding on the [CancellableTaskResult.map2 example](../cancellableTaskResult/map2.md#example-1), we define another function: 12 | 13 | ```fsharp 14 | notifyFollowers : NotifyNewPostRequest -> CancellableTask> 15 | ``` 16 | 17 | We can then rewrite the example and additionally call `notifyFollowers` using the operators as below: 18 | 19 | ```fsharp 20 | open FsToolkit.ErrorHandling.Operator.CancellableTaskResult 21 | 22 | // CreatePostRequest -> CancellableTask> 23 | let createPostAndNotifyFollowers (req : CreatePostRequest) = 24 | notifyNewPostRequest 25 | (getFollowerIds req.UserId) 26 | <*> (createPost req) 27 | >>= notifyFollowers 28 | ``` 29 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/apply.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskValidation.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | CancellableTask 'b), 'c list>> 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/error.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskValidation 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `CancellableTaskValidation<'ok, 'error>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> CancellableTaskValidation<'ok, 'error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : CancellableTaskValidation = 20 | CancellableTaskValidation.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/index.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskValidation 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This module provides utility functions and infix operators to work with `CancellableTask>`. 6 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/map2.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskValidation.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | -> CancellableTask> 12 | ``` 13 | 14 | Like [Result.map2](../result/map2.md), but collects the errors from both arguments. 15 | 16 | ## Examples 17 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/map3.md: -------------------------------------------------------------------------------- 1 | ## CancellableTaskValidation.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> 'b -> 'c -> 'd) 9 | -> CancellableTask> 10 | -> CancellableTask> 11 | -> CancellableTask> 12 | -> CancellableTask> 13 | ``` 14 | 15 | Like [Result.map3](../result/map3.md), but collects the errors from all arguments. 16 | 17 | ## Examples 18 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/ofChoice.md: -------------------------------------------------------------------------------- 1 | # CancellableTaskValidation.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Choice<'T, 'Error>` into a `CancellableTask>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'T, 'Error> -> CancellableTask> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = CancellableTaskValidation.ofChoice (Choice1Of2 42) 19 | // cancellableTask { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = CancellableTaskValidation.ofChoice (Choice2Of2 "error") 26 | // cancellableTask { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/cancellableTaskValidation/ofResult.md: -------------------------------------------------------------------------------- 1 | # CancellableTaskValidation.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into a `CancellableTask>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> CancellableTask> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = CancellableTaskValidation.ofResult (Ok 42) 19 | // cancellableTask { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = CancellableTaskValidation.ofResult (Error "error") 26 | // cancellableTask { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/jobOption/ce.md: -------------------------------------------------------------------------------- 1 | ## JobOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | tryParseInt : string -> Option 13 | tryFindPersonById : int -> Job> 14 | updatePerson : Person -> Job 15 | ``` 16 | 17 | ```fsharp 18 | // Job> 19 | let addResult = jobOption { 20 | let! personId = tryParseInt "3001" 21 | let! age = tryParseInt "35" 22 | let! person = tryFindPersonById personId "US-OH" 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` -------------------------------------------------------------------------------- /gitbook/jobResult/apply.md: -------------------------------------------------------------------------------- 1 | ## JobResult.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Job 'b), 'c>> 9 | -> Job> 10 | -> Job> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/jobResult/bind.md: -------------------------------------------------------------------------------- 1 | ## JobResult.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Job>) 9 | -> Job> 10 | -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` operations can also be solved using [the `jobResult` computation expression](../jobResult/ce.md). 16 | 17 | ### Example 1 18 | 19 | Continuing from the [JobResult.map2 example](../jobResult/map2.md#example-1) and given the function 20 | 21 | ```fsharp 22 | let notifyFollowers : NotifyNewPostRequest -> Job> 23 | ``` 24 | 25 | we can notify all followers using `JobResult.bind` as below: 26 | 27 | ```fsharp 28 | newPostRequestResult |> JobResult.bind notifyFollowers 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/jobResult/ce.md: -------------------------------------------------------------------------------- 1 | ## JobResult Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | 6 | ## Examples 7 | 8 | ### Example 1 9 | 10 | The initial [motivating example](../../) is perhaps more realistic if some functions are asynchronous. Given the following functions: 11 | 12 | ```fsharp 13 | tryGetUser : string -> Job 14 | isPwdValid : string -> User -> bool 15 | authorize : User -> Job> 16 | createAuthToken : User -> Result 17 | ``` 18 | 19 | A login flow can be implemented as below using the `jobResult` CE and a few [helpers](others.md): 20 | 21 | ```fsharp 22 | type LoginError = 23 | | InvalidUser 24 | | InvalidPwd 25 | | Unauthorized of AuthError 26 | | TokenErr of TokenError 27 | 28 | let login (username: string) (password: string) : Job> = 29 | jobResult { 30 | let! user = username |> tryGetUser |> JobResult.requireSome InvalidUser 31 | do! user |> isPwdValid password |> Result.requireTrue InvalidPwd 32 | do! user |> authorize |> JobResult.mapError Unauthorized 33 | return! user |> createAuthToken |> Result.mapError TokenErr 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /gitbook/jobResult/error.md: -------------------------------------------------------------------------------- 1 | ## JobResult.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Job>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Job> = 20 | JobResult.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/jobResult/foldResult.md: -------------------------------------------------------------------------------- 1 | ## JobResult.foldResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> ('c -> 'b) -> Job> -> Job<'b> 9 | ``` 10 | 11 | This is just a shortcut for `Job.map Result.fold`. See [Result.fold](../result/fold.md) for more. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | type HttpResponse<'a, 'b> = 19 | | Ok of 'a 20 | | InternalError of 'b 21 | 22 | // CreatePostRequest -> Job> 23 | let createPost (req : CreatePostRequest) = job { 24 | // ... 25 | } 26 | 27 | // Job 28 | let handler (httpReq : HttpRequest) = 29 | // ... 30 | 31 | // Job> 32 | let createPostJR = createPost httpReq 33 | 34 | createPostJR 35 | |> JobResult.fold Ok InternalError 36 | ``` 37 | -------------------------------------------------------------------------------- /gitbook/jobResult/fromTask.md: -------------------------------------------------------------------------------- 1 | # JobResult.fromTask 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task<'T>` into a `Job>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'T> -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = JobResult.fromTask (task { return 42 }) 19 | // job { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = JobResult.fromTask (task { return System.Exception("error") }) 26 | // job { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/jobResult/fromUnitTask.md: -------------------------------------------------------------------------------- 1 | # JobResult.fromTask 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task` into a `Job>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = JobResult.fromUnitTask (task { return () }) 19 | // job { return Ok () } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = JobResult.fromUnitTask (task { return System.Exception("error") }) 26 | // job { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/jobResult/ignore.md: -------------------------------------------------------------------------------- 1 | ## JobResult.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Job> -> Job> 9 | ``` 10 | 11 | This is a shortcut for `JobResult.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> Job> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `JobResult.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = jobResult { 25 | do! savePost createPostRequest |> JobResult.ignore 26 | } 27 | ``` -------------------------------------------------------------------------------- /gitbook/jobResult/map.md: -------------------------------------------------------------------------------- 1 | ## JobResult.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Job> -> Job> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `map` operations can also be solved using [the `jobResult` computation expression](../jobResult/ce.md). 14 | 15 | ### Example 1 16 | 17 | As a continuation of [Result.map3 Example 2](../result/map3.md#example-2), let's assume that we want to store the created post in the database using the function 18 | 19 | ```fsharp 20 | savePost : CreatePostRequest -> Job> 21 | ``` 22 | 23 | We can save the post and return its inner using `JobResult.map`: 24 | 25 | ```fsharp 26 | let rawPostId : Job> = 27 | savePost createPostRequest 28 | |> JobResult.map (fun (PostId postId) -> postId) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/jobResult/map3.md: -------------------------------------------------------------------------------- 1 | ## JobResult.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Job> 10 | -> Job> 11 | -> Job> 12 | -> Job> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `jobResult` computation expression](../jobResult/ce.md). -------------------------------------------------------------------------------- /gitbook/jobResult/mapError.md: -------------------------------------------------------------------------------- 1 | ## JobResult.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Job> -> Job> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | From the [JobResult.map](../jobResult/map.md#example-1) example, if we want to map the error part alone, we can do it as below: 16 | 17 | ```fsharp 18 | // Job, string> 19 | createPost createPostRequest 20 | |> JobResult.mapError (fun (ex : exn) -> ex.Message) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/jobResult/ofAsync.md: -------------------------------------------------------------------------------- 1 | # JobResult.ofAsync 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Async<'T>` into an `Job>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Async<'T> -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = JobResult.ofAsync (async { return 42 }) 19 | // job { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = JobResult.ofAsync (async { return System.Exception("error") }) 26 | // job { return Error System.Exception("error") } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/jobResult/ofJob.md: -------------------------------------------------------------------------------- 1 | # JobResult.ofJob 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Job<'T>` into an `Job>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Job<'T> -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = JobResult.ofJob (job { return 42 }) 19 | // job { return Ok 42 } 20 | ``` 21 | -------------------------------------------------------------------------------- /gitbook/jobResult/ofResult.md: -------------------------------------------------------------------------------- 1 | # JobResult.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into an `Job>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Job> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = JobResult.ofResult (Ok 42) 19 | // job { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = JobResult.ofResult (Error "error") 26 | // job { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/jobResult/operators.md: -------------------------------------------------------------------------------- 1 | ## JobResult Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.JobResult` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `Job>` type. 6 | 7 | ## Examples: 8 | 9 | ### Example 1 10 | 11 | Expanding on the [JobResult.map2 example](../jobResult/map2.md#example-1), we define another function: 12 | 13 | ```fsharp 14 | notifyFollowers : NotifyNewPostRequest -> Job> 15 | ``` 16 | 17 | We can then rewrite the example and additionally call `notifyFollowers` using the operators as below: 18 | 19 | ```fsharp 20 | open FsToolkit.ErrorHandling.Operator.JobResult 21 | 22 | // CreatePostRequest -> Job> 23 | let createPostAndNotifyFollowers (req : CreatePostRequest) = 24 | notifyNewPostRequest 25 | (getFollowerIds req.UserId) 26 | <*> (createPost req) 27 | >>= notifyFollowers 28 | ``` 29 | -------------------------------------------------------------------------------- /gitbook/list/sequenceAsyncResultA.md: -------------------------------------------------------------------------------- 1 | ## List.sequenceAsyncResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Async> list -> Async> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [List.traverseAsyncResultA](traverseAsyncResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [sequenceResultA](sequenceResultA.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | 21 | -------------------------------------------------------------------------------- /gitbook/list/sequenceAsyncResultM.md: -------------------------------------------------------------------------------- 1 | ## List.sequenceAsyncResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Async> list -> Async> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [List.traverseAsyncResultM](traverseAsyncResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [sequenceResultM](sequenceResultM.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples -------------------------------------------------------------------------------- /gitbook/list/sequenceTaskResultA.md: -------------------------------------------------------------------------------- 1 | ## List.sequenceTaskResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Task> list -> Task> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [List.traverseTaskResultA](traverseTaskResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [sequenceResultA](sequenceResultA.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | 21 | -------------------------------------------------------------------------------- /gitbook/list/sequenceTaskResultM.md: -------------------------------------------------------------------------------- 1 | ## List.sequenceTaskResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Task> list -> Task> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [List.traverseTaskResultM](traverseTaskResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [sequenceResultM](sequenceResultM.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples -------------------------------------------------------------------------------- /gitbook/list/traverseAsyncResultA.md: -------------------------------------------------------------------------------- 1 | ## List.traverseAsyncResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Async>) -> 'a list -> Async> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [List.sequenceAsyncResultA](sequenceAsyncResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [traverseResultA](traverseResultA.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/list/traverseAsyncResultM.md: -------------------------------------------------------------------------------- 1 | ## List.traverseAsyncResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Async>) -> 'a list -> Async> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [List.sequenceAsyncResultM](sequenceAsyncResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [traverseResultM](traverseResultM.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples -------------------------------------------------------------------------------- /gitbook/list/traverseTaskResultA.md: -------------------------------------------------------------------------------- 1 | ## List.traverseTaskResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Task>) -> 'a list -> Task> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [List.sequenceTaskResultA](sequenceTaskResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [traverseResultA](traverseResultA.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/list/traverseTaskResultM.md: -------------------------------------------------------------------------------- 1 | ## List.traverseTaskResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Task>) -> 'a list -> Task> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [List.sequenceTaskResultM](sequenceTaskResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [traverseResultM](traverseResultM.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples -------------------------------------------------------------------------------- /gitbook/option/bind.md: -------------------------------------------------------------------------------- 1 | # Option.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | ('TInput -> 'TOutput option) -> 'TInput option -> 'TOutput option 9 | ``` 10 | 11 | ## Examples 12 | 13 | Take the following function for example 14 | 15 | ```fsharp 16 | // string -> int option 17 | let tryParseInt (s: string) = 18 | match Int32.TryParse(s) with 19 | | true, i -> Some i 20 | | false, _ -> None 21 | ``` 22 | 23 | ### Example 1 24 | 25 | ```fsharp 26 | let opt : int option = 27 | Some "123" // string option 28 | |> Option.bind tryParseInt // int option 29 | 30 | // Some 123 31 | ``` 32 | 33 | ### Example 2 34 | 35 | ```fsharp 36 | let opt : int option = 37 | Some "Not a number" // string option 38 | |> Option.bind tryParseInt // int option 39 | 40 | // None 41 | ``` 42 | 43 | ### Example 3 44 | 45 | ```fsharp 46 | let opt : int option = 47 | None // string option 48 | |> Option.bind tryParseInt // int option 49 | 50 | // None 51 | ``` 52 | -------------------------------------------------------------------------------- /gitbook/option/bindNull.md: -------------------------------------------------------------------------------- 1 | # Option.bindNull 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | ('T -> 'nullableValue) -> 'T option -> 'nullableValue option 9 | ``` 10 | 11 | ## Examples 12 | 13 | 14 | ### Example 1 15 | 16 | ```fsharp 17 | open System 18 | 19 | let userInput = Some 12 20 | let toNullable<'T> x = Nullable x 21 | 22 | Option.bindNull toNullable userInput 23 | // Some 12 24 | ``` 25 | 26 | ### Example 2 27 | 28 | ```fsharp 29 | open System 30 | 31 | let userInput : Option = None 32 | let toNullable<'T> x = Nullable x 33 | 34 | Option.bindNull toNullable userInput 35 | // None 36 | ``` 37 | 38 | ### Example 3 39 | 40 | ```fsharp 41 | let userInput = Some 12 42 | Option.bindNull string userInput 43 | // Some "12" 44 | ``` 45 | 46 | 47 | -------------------------------------------------------------------------------- /gitbook/option/ce.md: -------------------------------------------------------------------------------- 1 | ## Option Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | ```fsharp 10 | // Option 11 | let addResult = option { 12 | let! x = tryParseInt "35" 13 | let! y = tryParseInt "5" 14 | let! z = tryParseInt "2" 15 | return add x y z 16 | } 17 | ``` 18 | 19 | ### Example 2 20 | 21 | Example taken from [here](https://github.com/lukaszkrzywizna/learn-fsharp/blob/feature/9-finito/LearnFsharp/Lesson.fs#L436-L456) 22 | 23 | ```fsharp 24 | // int -> int -> int option 25 | let tryDivide x y = 26 | match y with 27 | | 0 -> None 28 | | _ -> Some (x / y) 29 | 30 | // int -> int -> int option 31 | let multiplyIfEven x y = 32 | match y % 2 with 33 | | 0 -> Some <| x * y 34 | | _ -> None 35 | 36 | // int option 37 | let resultNone = option { 38 | let! result = tryDivide 5 3 39 | let mapped = result * 5 40 | return! multiplyIfEven 5 mapped 41 | } 42 | // result: None 43 | 44 | // int option 45 | let resultSome = option { 46 | let! result = tryDivide 6 3 47 | let mapped = result * 5 48 | return! multiplyIfEven 5 mapped 49 | } 50 | // result: Some 50 51 | 52 | ``` 53 | -------------------------------------------------------------------------------- /gitbook/option/either.md: -------------------------------------------------------------------------------- 1 | # Option.either 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | Provide two functions to execute depending on the value of the option. If the option is `Some`, the first function will be executed. If the option is `None`, the second function will be executed. 8 | 9 | ```fsharp 10 | ('T-> 'output) -> (unit -> 'output) -> 'T option -> 'output 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Option.either (fun x -> x * 2) (fun () -> 0) (Some 5) 19 | 20 | // 10 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | Option.either (fun x -> x * 2) (fun () -> 0) None 27 | 28 | // 0 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/option/map.md: -------------------------------------------------------------------------------- 1 | # Option.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of an option if it is `Some`. If the option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('TInput-> 'TOutput) -> 'TInput option -> 'TOutput option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Option.map (fun x -> x + 1) (Some 1) 19 | 20 | // Some 2 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | Option.map (fun x -> x + 1) None 27 | 28 | // None 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/option/map2.md: -------------------------------------------------------------------------------- 1 | # Option.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the values of two options if they are `Some`. If either option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('TInput1 -> 'TInput2 -> 'TOutput) -> 'TInput1 option -> 'TInput2 option -> 'TOutput option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Option.map2 (fun x y -> x + y) (Some 1) (Some 2) 19 | 20 | // Some 3 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | Option.map2 (fun x y -> x + y) (Some 1) None 27 | 28 | // None 29 | ``` 30 | 31 | ### Example 3 32 | 33 | ```fsharp 34 | Option.map2 (fun x y -> x + y) None (Some 2) 35 | 36 | // None 37 | ``` 38 | -------------------------------------------------------------------------------- /gitbook/option/map3.md: -------------------------------------------------------------------------------- 1 | # Option.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the values of three options if they are `Some`. If any option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('TInput1 -> 'TInput2 -> 'TInput3 -> 'TOutput) -> 'TInput1 option -> 'TInput2 option -> 'TInput3 option -> 'TOutput option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Option.map3 (fun x y z -> x + y + z) (Some 1) (Some 2) (Some 3) 19 | 20 | // Some 6 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | Option.map3 (fun x y z -> x + y + z) (Some 1) (Some 2) None 27 | 28 | // None 29 | ``` 30 | 31 | ### Example 3 32 | 33 | ```fsharp 34 | Option.map3 (fun x y z -> x + y + z) (Some 1) None (Some 3) 35 | 36 | // None 37 | ``` 38 | 39 | ### Example 4 40 | 41 | ```fsharp 42 | Option.map3 (fun x y z -> x + y + z) None (Some 2) (Some 3) 43 | 44 | // None 45 | ``` 46 | -------------------------------------------------------------------------------- /gitbook/option/ofNull.md: -------------------------------------------------------------------------------- 1 | # Option.ofNull 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `nullableValue` value to `'nullableValue Option`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'nullableValue -> 'nullableValue Option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let opt = Option.ofNull 1 19 | // Some 1 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let opt = Option.ofNull null 26 | // None 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/option/ofPair.md: -------------------------------------------------------------------------------- 1 | # Option.ofPair 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `bool * 'T` value to `'T Option`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | bool * 'T -> 'T Option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let opt = Option.ofPair (true, 1) 19 | // Some 1 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let opt = Option.ofPair (false, 1) 26 | // None 27 | ``` 28 | 29 | ### Example 3 30 | 31 | Instead of using this code snippet, 32 | 33 | ```fsharp 34 | match Int32.TryParse "12" with 35 | | true, x -> x 36 | | false, _ -> 0 37 | 38 | // 12 39 | ``` 40 | 41 | you could use `Option.ofPair` if it better suits your use case 42 | 43 | ```fsharp 44 | match Int32.TryParse "12" |> Option.ofPair with 45 | | Some x -> x 46 | | None -> 0 47 | 48 | // 12 49 | ``` 50 | -------------------------------------------------------------------------------- /gitbook/option/ofResult.md: -------------------------------------------------------------------------------- 1 | # Option.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` value to `'T Option`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> 'T Option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let opt = Option.ofResult (Ok 1) 19 | // Some 1 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let opt = Option.ofResult (Error "error") 26 | // None 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/option/ofValueOption.md: -------------------------------------------------------------------------------- 1 | # Option.ofValueOption 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `'T voption` value to `'T Option`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'T voption -> 'T Option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let x : int voption = Some 1 19 | let opt = Option.ofValueOption x 20 | // Some 1 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | let x : int voption = None 27 | let opt = Option.ofValueOption x 28 | // None 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/option/sequenceAsync.md: -------------------------------------------------------------------------------- 1 | ## Option.sequenceAsync 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async<'a> option -> Async<'a option> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Option.traverseAsync](traverseAsync.md). 12 | 13 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | ```fsharp 20 | let a1 : Async = 21 | Option.sequenceAsync (Some (Async.singleton 42)) 22 | // async { return Some 42 } 23 | 24 | let a2 : Async = 25 | Option.sequenceAsync None 26 | // async { return None } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/option/sequenceAsyncResult.md: -------------------------------------------------------------------------------- 1 | ## Option.sequenceAsyncResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Async> option -> Async, 'e> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Option.traverseAsyncResult](traverseAsyncResult.md). 12 | 13 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | ```fsharp 20 | let r1 : Async> = 21 | Some (async { return Ok 42 }) |> Option.sequenceAsyncResult 22 | // async { return Ok (Some 42) } 23 | 24 | let r2 : Async> = 25 | Some (async { return Error "something went wrong" }) |> Option.sequenceAsyncResult 26 | // async { return Error "something went wrong" } 27 | 28 | let r3 : Async> = 29 | None |> Option.sequenceAsyncResult 30 | // async { return Ok None } 31 | ``` 32 | -------------------------------------------------------------------------------- /gitbook/option/sequenceOptionM.md: -------------------------------------------------------------------------------- 1 | # List.sequenceOptionM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Applies the monadic function `id` to each element in the input list, and returns the result as an option. If any element in the list is None, the entire result will be None. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'a option list -> 'a list option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let myList = 19 | [ 20 | Some 123 21 | Some 456 22 | Some 789 23 | ] 24 | 25 | List.sequenceOptionM myList 26 | // Some [123; 456; 789] 27 | ``` 28 | 29 | ### Example 2 30 | 31 | ```fsharp 32 | let myList = 33 | [ 34 | Some 123 35 | None 36 | Some 789 37 | ] 38 | 39 | List.sequenceOptionM myList 40 | // None 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/option/sequenceResult.md: -------------------------------------------------------------------------------- 1 | ## Option.sequenceResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<'a,'b> option -> Result<'a option, 'b> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Option.traverseResult](traverseResult.md). 12 | 13 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | ```fsharp 20 | let r1 : Result = 21 | Option.sequenceResult (Some (Ok 42)) 22 | // Ok (Some 42) 23 | 24 | let r2 : Result = 25 | Option.sequenceResult (Some (Error "something went wrong")) 26 | // Error "something went wrong" 27 | 28 | let r3 : Result = 29 | Option.sequenceResult None 30 | // Ok None 31 | ``` 32 | -------------------------------------------------------------------------------- /gitbook/option/sequenceTask.md: -------------------------------------------------------------------------------- 1 | ## Option.sequenceTask 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task<'a> option -> Task<'a option> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Option.traverseTask](traverseTask.md). 12 | 13 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | ```fsharp 20 | let a1 : Task = 21 | Option.sequenceTask (Some (Task.singleton 42)) 22 | // async { return Some 42 } 23 | 24 | let a2 : Task = 25 | Option.sequenceTask None 26 | // async { return None } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/option/sequenceTaskResult.md: -------------------------------------------------------------------------------- 1 | ## Option.sequenceTaskResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task> option -> Task, 'e> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Option.traverseTaskResult](traverseTaskResult.md). 12 | 13 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | ```fsharp 20 | let r1 : Task> = 21 | Some (task { return Ok 42 }) |> Option.sequenceTaskResult 22 | // task { return Ok (Some 42) } 23 | 24 | let r2 : Task> = 25 | Some (task { return Error "something went wrong" }) |> Option.sequenceTaskResult 26 | // task { return Error "something went wrong" } 27 | 28 | let r3 : Task> = 29 | None |> Option.sequenceTaskResult 30 | // task { return Ok None } 31 | ``` 32 | -------------------------------------------------------------------------------- /gitbook/option/sequenceVOptionM.md: -------------------------------------------------------------------------------- 1 | # List.sequenceVOptionM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Applies the monadic function `id` to each element in the input list, and returns the result as an option. If any element in the list is ValueNone, the entire result will be ValueNone. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'a voption list -> 'a list voption 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let myList = 19 | [ 20 | ValueSome 123 21 | ValueSome 456 22 | ValueSome 789 23 | ] 24 | 25 | List.sequenceVOptionM myList 26 | // ValueSome [123; 456; 789] 27 | ``` 28 | 29 | ### Example 2 30 | 31 | ```fsharp 32 | let myList = 33 | [ 34 | ValueSome 123 35 | ValueNone 36 | ValueSome 789 37 | ] 38 | 39 | List.sequenceVOptionM myList 40 | // ValueNone 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/option/toValueOption.md: -------------------------------------------------------------------------------- 1 | # Option.toValueOption 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `'T Option` value to `'T voption`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'T Option -> 'T voption 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let opt = Option.toValueOption (Some 1) 19 | // Some 1 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let opt = Option.toValueOption None 26 | // None 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/option/traverseOptionM.md: -------------------------------------------------------------------------------- 1 | # List.traverseOptionM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Applies the given function to each element in the input list, and returns an option containing a list of the results. If any of the function applications return None, the entire result will be None. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('a -> 'b option) -> 'a list -> 'b list option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let tryParseInt (s: string) = 19 | match Int32.TryParse(s) with 20 | | true, i -> Some i 21 | | false, _ -> None 22 | 23 | let myList = ["123"; "456"; "789"] 24 | 25 | List.traverseOptionM tryParseInt myList 26 | // Some [123; 456; 789] 27 | ``` 28 | 29 | ### Example 2 30 | 31 | ```fsharp 32 | let tryParseInt (s: string) = 33 | match Int32.TryParse(s) with 34 | | true, i -> Some i 35 | | false, _ -> None 36 | 37 | let myList = ["123"; "Not a number"; "789"] 38 | 39 | List.traverseOptionM tryParseInt myList 40 | // None 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/option/traverseVOptionM.md: -------------------------------------------------------------------------------- 1 | # List.traverseVOptionM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Applies the given function to each element in the input list, and returns an option containing a list of the results. If any of the function applications return None, the entire result will be None. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('a -> 'b voption) -> 'a list -> 'b list voption 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let tryParseInt (s: string) = 19 | match Int32.TryParse(s) with 20 | | true, i -> ValueSome i 21 | | false, _ -> ValueNone 22 | 23 | let myList = ["123"; "456"; "789"] 24 | 25 | List.traverseVOptionM tryParseInt myList 26 | // Some [123; 456; 789] 27 | ``` 28 | 29 | ### Example 2 30 | 31 | ```fsharp 32 | let tryParseInt (s: string) = 33 | match Int32.TryParse(s) with 34 | | true, i -> ValueSome i 35 | | false, _ -> ValueNone 36 | 37 | let myList = ["123"; "Not a number"; "789"] 38 | 39 | List.traverseVOptionM tryParseInt myList 40 | // None 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/option/zip.md: -------------------------------------------------------------------------------- 1 | # Option.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Takes two options and returns a tuple of the pair or None if either are None 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | 'left option -> 'right option -> ('left * 'right) option 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let left = Some 123 19 | let right = Some "abc" 20 | 21 | Option.zip left right 22 | // Some (123, "abc") 23 | ``` 24 | 25 | ### Example 2 26 | 27 | ```fsharp 28 | let left = Some 123 29 | let right = None 30 | 31 | Option.zip left right 32 | // None 33 | ``` 34 | -------------------------------------------------------------------------------- /gitbook/parallelAsyncResult/map3.md: -------------------------------------------------------------------------------- 1 | ## ParallelAsyncResult.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | -> Async> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map3` operations can also be solved using [the `parallelAsyncResult` computation expression](../parallelAsyncResult/ce.md). -------------------------------------------------------------------------------- /gitbook/parallelAsyncValidation/map2.md: -------------------------------------------------------------------------------- 1 | ## ParallelAsyncValidation.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | ``` 13 | 14 | Like [ParallelAsyncResult.map2](../parallelAsyncResult/map2.md), but collects the errors from both arguments. 15 | -------------------------------------------------------------------------------- /gitbook/parallelAsyncValidation/map3.md: -------------------------------------------------------------------------------- 1 | ## ParallelAsyncValidation.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Async> 10 | -> Async> 11 | -> Async> 12 | -> Async> 13 | ``` 14 | 15 | Like [ParallelAsyncResult.map3](../parallelAsyncResult/map3.md), but collects the errors from all arguments. 16 | 17 | -------------------------------------------------------------------------------- /gitbook/pr.md: -------------------------------------------------------------------------------- 1 | # Sorry, this page is not yet documented 2 | 3 | This feature is supported in the library, but we have not got to documenting it yet. Feel free to open an [issue or PR](https://github.com/demystifyfp/FsToolkit.ErrorHandling) to add documentation for this feature. 4 | -------------------------------------------------------------------------------- /gitbook/result/ignore.md: -------------------------------------------------------------------------------- 1 | # Result.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This is a shortcut for `Result.map ignore`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'a, 'b> -> Result 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> Result 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `Result.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = result { 25 | do! savePost createPostRequest |> Result.ignore 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/result/map.md: -------------------------------------------------------------------------------- 1 | # Result.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `map` applies a transformation to the value inside a `Result` if it represents a successful result (`Ok`). It allows you to perform a computation on the value while preserving the success/error status of the original `Result`. If the original `Result` is an `Error`, `map` does nothing and returns the same `Error` unchanged. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('okInput -> 'okOutput) -> Result<'okInput, 'error> -> Result<'okOutput, 'error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Take the following functions for example 16 | 17 | ```fsharp 18 | // string -> int 19 | let remainingCharacters (prompt: string) = 20 | 280 - prompt.Length 21 | ``` 22 | 23 | ### Example 1 24 | 25 | ```fsharp 26 | let result = 27 | Ok "foo" // Result 28 | |> Result.map remainingCharacters // Result 29 | 30 | // Ok 277 31 | ``` 32 | 33 | ### Example 2 34 | 35 | ```fsharp 36 | let result = 37 | Error "bad things happened" // Result 38 | |> Result.map remainingCharacters // Result 39 | 40 | // Error "bad things happened" 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/result/mapError.md: -------------------------------------------------------------------------------- 1 | # Result.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `mapError` takes a result and a normal function and returns a new result value based on the input error value and the function 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput -> 'errorOutput) -> Result<'ok, 'errorInput> 11 | -> Result<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (message: string) = 21 | match message with 22 | | "bad things happened" -> 1 23 | | _ -> 0 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | Ok "all good" // Result 31 | |> Result.mapError getErrorCode // Result 32 | 33 | // Ok "all good" 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result = 40 | Error "bad things happened" // Result 41 | |> Result.mapError getErrorCode // Result 42 | 43 | // Error 1 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/result/ofChoice.md: -------------------------------------------------------------------------------- 1 | # Result.ofChoice 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms F#'s `Choice` value to `Result`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'a,'b> -> Result<'a, 'b> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Result.ofChoice (Choice1Of2 42) 19 | // Ok 42 20 | 21 | Result.ofChoice (Choice2Of2 "Something went wrong!") 22 | // Error "Something went wrong!" 23 | ``` 24 | -------------------------------------------------------------------------------- /gitbook/result/zip.md: -------------------------------------------------------------------------------- 1 | # Result.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Result<'leftOk, 'error> -> Result<'rightOk, 'error> -> Result<'leftOk * 'rightOk, 'error> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = Result.zip (Ok 1) (Ok 2) 17 | // Ok (1, 2) 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = Result.zip (Ok 1) (Error "Bad") 24 | // Error "Bad" 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = Result.zip (Error "Bad1") (Error "Bad2") 31 | // Error "Bad1" 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/result/zipError.md: -------------------------------------------------------------------------------- 1 | # Result.zipError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Result<'ok, 'leftError> -> Result<'ok, 'rightError> -> Result<'ok, 'leftError * 'rightError> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = Result.zipError (Ok 1) (Ok 2) 17 | // Ok 1 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = Result.zipError (Ok 1) (Error "Bad") 24 | // Ok 1 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = Result.zipError (Error "Bad1") (Error "Bad2") 31 | // Error("Bad1", "Bad2") 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/resultOption/apply.md: -------------------------------------------------------------------------------- 1 | # ResultOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<('a -> 'b) option, 'c> -> Result<'a option, 'c> 9 | -> Result<'b option, 'c> 10 | ``` 11 | 12 | ## Examples 13 | 14 | Take the following function for example 15 | 16 | ```fsharp 17 | // string -> int 18 | let characterCount (s: string) = s.Length 19 | ``` 20 | 21 | ### Example 1 22 | 23 | ```fsharp 24 | let result = 25 | Ok(Some "foo") // Result 26 | |> ResultOption.apply (Ok(Some characterCount)) // Result 27 | 28 | // Ok (Some 3) 29 | ``` 30 | 31 | ### Example 2 32 | 33 | ```fsharp 34 | let result = 35 | Ok None // Result 36 | |> ResultOption.apply (Ok(Some characterCount)) // Result 37 | 38 | // Ok None 39 | ``` 40 | 41 | ### Example 3 42 | 43 | ```fsharp 44 | let result = 45 | Error "bad things happened" // Result 46 | |> ResultOption.apply (Ok(Some characterCount)) // Result 47 | 48 | // Error "bad things happened" 49 | ``` 50 | -------------------------------------------------------------------------------- /gitbook/resultOption/ignore.md: -------------------------------------------------------------------------------- 1 | # ResultOption.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<'a option, 'b> -> Result 9 | ``` 10 | 11 | This is a shortcut for `ResultOption.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let deletePostIfExists : DeletePostRequest -> Result 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `ResultOption.ignore` as below: 22 | 23 | ```fsharp 24 | let deletePost = resultOption { 25 | do! deletePostIfExists deletePostRequest |> ResultOption.ignore 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/resultOption/map.md: -------------------------------------------------------------------------------- 1 | # ResultOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Result<'a option, 'c> -> Result<'b option, 'c> 9 | ``` 10 | 11 | `ResultOption.map` is the same as `Result.map Option.map`. 12 | 13 | ## Examples 14 | 15 | Take the following functions for example 16 | 17 | ```fsharp 18 | // string -> int 19 | let remainingCharacters (prompt: string) = 20 | 280 - prompt.Length 21 | ``` 22 | 23 | ### Example 1 24 | 25 | ```fsharp 26 | let result = 27 | Ok(Some "foo") // Result 28 | |> ResultOption.map remainingCharacters // Result 29 | 30 | // Ok (Some 277) 31 | ``` 32 | 33 | ### Example 2 34 | 35 | ```fsharp 36 | let result = 37 | Ok None // Result 38 | |> ResultOption.map remainingCharacters // Result 39 | 40 | // Ok None 41 | ``` 42 | 43 | ### Example 3 44 | 45 | ```fsharp 46 | let result = 47 | Error "bad things happened" // Result 48 | |> ResultOption.map remainingCharacters // Result 49 | 50 | // Error "bad things happened" 51 | ``` 52 | -------------------------------------------------------------------------------- /gitbook/resultOption/map3.md: -------------------------------------------------------------------------------- 1 | # ResultOption.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Result<'a option, 'e> 10 | -> Result<'b option, 'e> 11 | -> Result<'c option, 'e> 12 | -> Result<'d option, 'e> 13 | ``` 14 | 15 | ## Examples 16 | 17 | ### Example 1 18 | 19 | Given the following function: 20 | 21 | ```fsharp 22 | add : int -> int -> int -> int 23 | ``` 24 | 25 | Then using `ResultOption.map3`, we can do the following: 26 | 27 | ```fsharp 28 | ResultOption.map3 add (Ok (Some 30)) (Ok (Some 10)) (Ok (Some 2)) 29 | // Ok (Some 42) 30 | ``` 31 | -------------------------------------------------------------------------------- /gitbook/resultOption/mapError.md: -------------------------------------------------------------------------------- 1 | ## ResultOption.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('errorInput -> 'errorOutput) -> Result<'ok option, 'errorInput> -> Result<'ok option, 'errorOutput> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | From the [ResultOption.map](../resultOption/map.md#example-3) example, if we want to map the error part alone, we can do it as below: 16 | 17 | ```fsharp 18 | // string -> int 19 | let getErrorCode (message: string) = 20 | match message with 21 | | "bad things happened" -> 1 22 | | _ -> 0 23 | 24 | let result : Result = 25 | Error "bad things happened" // Result 26 | |> ResultOption.mapError getErrorCode // Result 27 | 28 | // Error 1 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/resultOption/ofChoice.md: -------------------------------------------------------------------------------- 1 | # ResultOption.ofChoice 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Choice<'T, 'Error>` value to `Result<'T option, 'Error>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'T, 'Error> -> Result<'T option, 'Error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = ResultOption.ofChoice (Choice1Of2 42) 19 | // Ok (Some 42) 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = ResultOption.ofChoice (Choice2Of2 "error") 26 | // Error "error" 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/resultOption/ofOption.md: -------------------------------------------------------------------------------- 1 | # ResultOption.ofOption 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `'T Option` value to `Result<'T option, 'Error>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Option<'T> -> Result<'T option, 'Error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = ResultOption.ofOption (Some 42) 19 | // Ok (Some 42) 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = ResultOption.ofOption None 26 | // Ok None 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/resultOption/ofResult.md: -------------------------------------------------------------------------------- 1 | # ResultOption.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` value to `Result<'T option, 'Error>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Result<'T option, 'Error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = ResultOption.ofResult (Ok 42) 19 | // Ok (Some 42) 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = ResultOption.ofResult (Error "error") 26 | // Error "error" 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/resultOption/zip.md: -------------------------------------------------------------------------------- 1 | # ResultOption.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<'leftOk option, 'error> -> Result<'rightOk option, 'error> -> Result<('leftOk * 'rightOk) option, 'error> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = ResultOption.zip (Ok(Some 1)) (Ok(Some 2)) 17 | // Ok (Some(1, 2)) 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = ResultOption.zip (Ok(Some 1)) (Ok None) 24 | // Ok None 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = ResultOption.zip (Ok(Some 1)) (Error "Bad") 31 | // Error "Bad" 32 | ``` 33 | 34 | ### Example 4 35 | 36 | ```fsharp 37 | let result = ResultOption.zip (Error "Bad1") (Error "Bad2") 38 | // Error "Bad1" 39 | ``` 40 | -------------------------------------------------------------------------------- /gitbook/resultOption/zipError.md: -------------------------------------------------------------------------------- 1 | # ResultOption.zipError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<'ok option, 'leftError> -> Result<'ok option, 'rightError> -> Result<'ok option, 'leftError * 'rightError> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = ResultOption.zip (Ok(Some 1)) (Ok(Some 2)) 17 | // Ok (Some 1) 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = ResultOption.zip (Ok(Some 1)) (Ok None) 24 | // Ok (Some 1) 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = ResultOption.zip (Ok(Some 1)) (Error "Bad") 31 | // Ok (Some 1) 32 | ``` 33 | 34 | ### Example 4 35 | 36 | ```fsharp 37 | let result = ResultOption.zip (Error "Bad1") (Error "Bad2") 38 | // Error("Bad1", "Bad2") 39 | ``` 40 | -------------------------------------------------------------------------------- /gitbook/script.fsx: -------------------------------------------------------------------------------- 1 | #I @"./../src/FsToolkit.ErrorHandling" 2 | #load "Result.fs" 3 | #load "Async.fs" 4 | #load "AsyncResult.fs" 5 | #load "ResultCE.fs" 6 | #load "AsyncResultCE.fs" 7 | #load "ResultOp.fs" 8 | #load "ResultOption.fs" 9 | #load "ResultOptionCE.fs" 10 | #load "ResultOptionOp.fs" 11 | #load "Validation.fs" 12 | #load "ValidationOp.fs" 13 | #load "Option.fs" 14 | #load "List.fs" 15 | 16 | open System 17 | open FsToolkit.ErrorHandling 18 | 19 | let tryParseInt (str: string) = 20 | match Int32.TryParse str with 21 | | true, x -> Ok x 22 | | false, _ -> Error(sprintf "unable to parse '%s' to integer" str) 23 | 24 | [ 25 | "1" 26 | "foo" 27 | "3" 28 | "bar" 29 | ] 30 | |> List.traverseResultA tryParseInt 31 | -------------------------------------------------------------------------------- /gitbook/seq/sequenceAsyncResultA.md: -------------------------------------------------------------------------------- 1 | ## Seq.sequenceAsyncResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Async> seq -> Async> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Seq.traverseAsyncResultA](traverseAsyncResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [sequenceResultA](sequenceResultA.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | 21 | -------------------------------------------------------------------------------- /gitbook/seq/sequenceAsyncResultM.md: -------------------------------------------------------------------------------- 1 | ## Seq.sequenceAsyncResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Async> seq -> Async> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Seq.traverseAsyncResultM](traverseAsyncResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [sequenceResultM](sequenceResultM.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/seq/sequenceTaskResultA.md: -------------------------------------------------------------------------------- 1 | ## Seq.sequenceTaskResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Task> seq -> Task> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Seq.traverseTaskResultA](traverseTaskResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [sequenceResultA](sequenceResultA.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | 21 | -------------------------------------------------------------------------------- /gitbook/seq/sequenceTaskResultM.md: -------------------------------------------------------------------------------- 1 | ## Seq.sequenceTaskResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | Task> seq -> Task> 9 | ``` 10 | 11 | Note that `sequence` is the same as `traverse id`. See also [Seq.traverseTaskResultM](traverseTaskResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [sequenceResultM](sequenceResultM.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/seq/traverseAsyncResultA.md: -------------------------------------------------------------------------------- 1 | ## Seq.traverseAsyncResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Async>) -> 'a seq -> Async> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [Seq.sequenceAsyncResultA](sequenceAsyncResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [traverseResultA](traverseResultA.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/seq/traverseAsyncResultM.md: -------------------------------------------------------------------------------- 1 | ## Seq.traverseAsyncResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Async>) -> 'a seq -> Async> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [Seq.sequenceAsyncResultM](sequenceAsyncResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [traverseResultM](traverseResultM.md) except that it uses `Async>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/seq/traverseTaskResultA.md: -------------------------------------------------------------------------------- 1 | ## Seq.traverseTaskResultA 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Task>) -> 'a seq -> Task> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [Seq.sequenceTaskResultA](sequenceTaskResultA.md). 12 | 13 | This is applicative, collecting all errors. 14 | 15 | This is the same as [traverseResultA](traverseResultA.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/seq/traverseTaskResultM.md: -------------------------------------------------------------------------------- 1 | ## Seq.traverseTaskResultM 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> Task>) -> 'a seq -> Task> 9 | ``` 10 | 11 | Note that `traverse` is the same as `map >> sequence`. See also [Seq.sequenceTaskResultM](sequenceTaskResultM.md). 12 | 13 | This is monadic, stopping on the first error. 14 | 15 | This is the same as [traverseResultM](traverseResultM.md) except that it uses `Task>` instead of `Result<_,_>`. 16 | 17 | See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/). 18 | 19 | ## Examples 20 | -------------------------------------------------------------------------------- /gitbook/task/apply.md: -------------------------------------------------------------------------------- 1 | # Task.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task<('a -> 'b)> -> Task<'a> -> Task<'b> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Take the following function for example 14 | 15 | ```fsharp 16 | // string -> int 17 | let characterCount (s: string) = s.Length 18 | ``` 19 | 20 | ### Example 1 21 | 22 | ```fsharp 23 | let result = 24 | Task.singleton "foo" // Task 25 | |> Task.apply (Task.singleton characterCount) // Task 26 | 27 | // task { 3 } 28 | ``` 29 | -------------------------------------------------------------------------------- /gitbook/task/bind.md: -------------------------------------------------------------------------------- 1 | ## Task.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Task<'b>>) -> Task<'a> -> Task<'b> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `bind` operations can also be solved using [the `task` computation expression](../task/ce.md). 14 | 15 | ### Example 1 16 | 17 | Continuing from the [Task.map2 example](../task/map2.md#example-1) and given the function 18 | 19 | ```fsharp 20 | let notifyFollowers : NotifyNewPostRequest -> Task 21 | ``` 22 | 23 | we can notify all followers using `Task.bind` as below: 24 | 25 | ```fsharp 26 | newPostRequestResult |> Task.bind notifyFollowers 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /gitbook/task/bindV.md: -------------------------------------------------------------------------------- 1 | ## Task.bindV 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Like [Task.bind](../task/bind.md), but taking a `ValueTask<'a>` as input 6 | 7 | Function Signature: 8 | 9 | ```fsharp 10 | ('a -> Task<'b>>) -> ValueTask<'a> -> Task<'b> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` operations can also be solved using [the `task` computation expression](../task/ce.md). 16 | 17 | ### Example 1 18 | 19 | Continuing from the [Task.map2 example](../task/map2.md#example-1 and given the function 20 | 21 | ```fsharp 22 | let notifyFollowers : NotifyNewPostRequest -> Task 23 | ``` 24 | 25 | and assuming `newPostRequestResult` has type `ValueTask` 26 | 27 | we can notify all followers using `Task.bindV` as below: 28 | 29 | ```fsharp 30 | newPostRequestResult |> Task.bindV notifyFollowers 31 | ``` 32 | 33 | -------------------------------------------------------------------------------- /gitbook/task/catch.md: -------------------------------------------------------------------------------- 1 | ## Task.catch 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Creates a `Task` that attempts to execute the provided task, returning `Choice1Of2` with the result if the task completes without exceptions, or `Choice2Of2` with the exception if an exception is thrown. 6 | 7 | Function Signature: 8 | 9 | ```fsharp 10 | Task<'a> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Given the function: 16 | 17 | ```fsharp 18 | let taskThrow () = 19 | task { 20 | failwith "something bad happened" 21 | return Error "" 22 | } 23 | ``` 24 | 25 | ### Example 1 26 | 27 | ```fsharp 28 | let result = Task.catch (Task.singleton 42) 29 | // task { Choice1Of2(42) } 30 | ``` 31 | 32 | ### Example 2 33 | 34 | ```fsharp 35 | let result = Task.catch (taskThrow ()) 36 | // task { Choice2Of2(exn("something bad happened")) } 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /gitbook/task/ce.md: -------------------------------------------------------------------------------- 1 | ## Task Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | parseInt : string -> int 13 | findPersonById : int -> Task 14 | updatePerson : Person -> Task 15 | ``` 16 | 17 | ```fsharp 18 | // Task 19 | let addResult = task { 20 | let personId = parseInt "3001" 21 | let age = parseInt "35" 22 | let! person = findPersonById personId 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` -------------------------------------------------------------------------------- /gitbook/task/ignore.md: -------------------------------------------------------------------------------- 1 | ## Task.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task<'a> -> Task 9 | ``` 10 | 11 | This is a shortcut for `Task.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> Task 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `Task.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = task { 25 | do! savePost createPostRequest |> Task.ignore 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/task/map.md: -------------------------------------------------------------------------------- 1 | # Task.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of a task. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('input-> 'output) -> Task<'input> -> Task<'output> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Task.map (fun x -> x + 1) (Task.singleton 1) 19 | 20 | // task { 2 } 21 | ``` 22 | 23 | 24 | -------------------------------------------------------------------------------- /gitbook/task/map2.md: -------------------------------------------------------------------------------- 1 | ## Task.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) -> Task<'a> -> Task<'b> -> Task<'c> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `map` operations can also be solved using [the `task` computation expression](../task/ce.md). 14 | 15 | ### Example 1 16 | 17 | Given the functions 18 | 19 | ```fsharp 20 | getFollowerIds : UserId -> Task 21 | createPost : CreatePostRequest -> Task 22 | ``` 23 | 24 | And the type 25 | 26 | ```fsharp 27 | type NotifyNewPostRequest = 28 | { UserIds : UserId list 29 | NewPostId : PostId } 30 | static member Create userIds newPostsId = 31 | {UserIds = userIds; NewPostId = newPostsId} 32 | ``` 33 | 34 | We can create a `NotifyNewPostRequest` using `Task.map2` as below: 35 | 36 | ```fsharp 37 | let createPostAndGetNotifyRequest (req : CreatePostRequest) = 38 | // Task 39 | let getFollowersResult = getFollowerIds req.UserId 40 | 41 | // Task 42 | let createPostResult = createPost req 43 | 44 | // Task 45 | let newPostRequestResult = 46 | Task.map2 47 | NotifyNewPostRequest.Create getFollowersResult createPostResult 48 | 49 | // ... 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /gitbook/task/map3.md: -------------------------------------------------------------------------------- 1 | # Task.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Task<'a> 10 | -> Task<'b> 11 | -> Task<'c> 12 | -> Task<'d> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `task` computation expression](../task/ce.md). 18 | 19 | ### Example 1 20 | 21 | Let's assume that we have an `add` function that adds three numbers: 22 | 23 | ```fsharp 24 | // int -> int -> int -> int 25 | let add a b c = a + b + c 26 | ``` 27 | 28 | And an another function that asynchronously retrieves an integer, say a person's age: 29 | 30 | ```fsharp 31 | type AccountId = int 32 | 33 | // AccountId -> Task 34 | let getAge accountId = 35 | task { 36 | let ages = [ 37 | (1, 19); 38 | (2, 21); 39 | (3, 34); 40 | (4, 47); 41 | (5, 55); 42 | ] 43 | return ages |> Map.ofList |> Map.find accountId 44 | } 45 | ``` 46 | 47 | With the help of `Result.map3` function, we can now do the following: 48 | 49 | ```fsharp 50 | let summedAges = 51 | Task.map3 add (getAge 1) (getAge 3) (getAge 5) 52 | // task { 108 } 53 | ``` 54 | -------------------------------------------------------------------------------- /gitbook/task/mapV.md: -------------------------------------------------------------------------------- 1 | # Task.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Like [Task.map](../task/map.md), but taking a `ValueTask<'a>` as input 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('input-> 'output) -> ValueTask<'input> -> Task<'output> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | Task.mapV (fun x -> x + 1) (ValueTask.FromResult(1)) 19 | 20 | // task { 2 } 21 | ``` 22 | -------------------------------------------------------------------------------- /gitbook/task/ofUnit.md: -------------------------------------------------------------------------------- 1 | # Task.ofUnit 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task` into a `Task` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task -> Task 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = Task.ofUnit (task { return () }) 19 | // task { return () } 20 | ``` 21 | -------------------------------------------------------------------------------- /gitbook/task/zip.md: -------------------------------------------------------------------------------- 1 | # Task.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Takes two tasks and returns a tuple of the pair 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'left> -> Task<'right> -> Task<('left * 'right)> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let left = Task.singleton 123 19 | let right = Task.singleton "abc" 20 | 21 | Task.zip left right 22 | // task { (123, "abc") } 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /gitbook/taskOption/apply.md: -------------------------------------------------------------------------------- 1 | # TaskOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task<('a -> 'b) option> -> Task<'a option> -> Task<'b option> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Take the following function for example 14 | 15 | ```fsharp 16 | // string -> int 17 | let characterCount (s: string) = s.Length 18 | ``` 19 | 20 | ### Example 1 21 | 22 | ```fsharp 23 | let result = 24 | TaskOption.some "foo" // Task 25 | |> TaskOption.apply (TaskOption.some characterCount) // Task 26 | 27 | // task { Some 3 } 28 | ``` 29 | 30 | ### Example 2 31 | 32 | ```fsharp 33 | let result = 34 | Task.singleton None // Task 35 | |> TaskOption.apply (TaskOption.some characterCount) // Task 36 | 37 | // task { None } 38 | ``` 39 | 40 | ### Example 3 41 | 42 | ```fsharp 43 | let result : Task = 44 | TaskOption.some "foo" // Task 45 | |> TaskOption.apply (Task.singleton None) // Task 46 | 47 | // task { None } 48 | ``` 49 | -------------------------------------------------------------------------------- /gitbook/taskOption/ce.md: -------------------------------------------------------------------------------- 1 | ## TaskOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | tryParseInt : string -> Option 13 | tryFindPersonById : int -> Task> 14 | updatePerson : Person -> Task 15 | ``` 16 | 17 | ```fsharp 18 | // Task> 19 | let addResult = taskOption { 20 | let! personId = tryParseInt "3001" 21 | let! age = tryParseInt "35" 22 | let! person = tryFindPersonById personId 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /gitbook/taskOption/either.md: -------------------------------------------------------------------------------- 1 | # TaskOption.either 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | Provide two functions to execute depending on the value of the option. If the option is `Some`, the first function will be executed. If the option is `None`, the second function will be executed. 8 | 9 | ```fsharp 10 | (onSome : 'T -> Task<'output>) 11 | -> (onNone : Task<'output>) 12 | -> (input : Task<'T option>) 13 | -> Task<'output> 14 | ``` 15 | 16 | ## Examples 17 | 18 | ### Example 1 19 | 20 | ```fsharp 21 | TaskOption.either (fun x -> task { x * 2 }) (task { 0 }) (TaskOption.some 5) 22 | 23 | // task { 10 } 24 | ``` 25 | 26 | ### Example 2 27 | 28 | ```fsharp 29 | TaskOption.either (fun x -> x * 2) (task { 0 }) None 30 | 31 | // task { 0 } 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /gitbook/taskOption/map.md: -------------------------------------------------------------------------------- 1 | # TaskOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of a task option if it is `Some`. If the option is `None`, return `None`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('input -> 'output) -> Task<'input option> -> Task<'output option> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | TaskOption.map (fun x -> x + 1) (TaskOption.some 1) 19 | 20 | // task { Some 2 } 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | TaskOption.map (fun x -> x + 1) (Task.singleton None) 27 | 28 | // task { None } 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/taskOption/others.md: -------------------------------------------------------------------------------- 1 | # Other TaskOption Functions 2 | 3 | ## defaultValue 4 | 5 | Returns the contained value if Some, otherwise returns the provided value 6 | 7 | ### Function Signature 8 | 9 | ```fsharp 10 | 'a -> Task<'a option> -> Task<'a> 11 | ``` 12 | 13 | ## defaultWith 14 | 15 | Returns the contained value if Some, otherwise evaluates the given function and returns the result. 16 | 17 | ### Function Signature 18 | 19 | ```fsharp 20 | (unit -> 'a) -> Task<'a option> -> Task<'a> 21 | ``` 22 | 23 | ## some 24 | 25 | Wraps the provided value in an Task<'a option> 26 | 27 | ### Function Signature 28 | 29 | ```fsharp 30 | 'a -> Task<'a option> 31 | ``` 32 | 33 | 34 | -------------------------------------------------------------------------------- /gitbook/taskOption/zip.md: -------------------------------------------------------------------------------- 1 | # TaskOption.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Takes two options and returns a tuple of the pair or None if either are None 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'left option> -> Task<'right option> -> Task<('left * 'right) option> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let left = TaskOption.some 123 19 | let right = TaskOption.some "abc" 20 | 21 | TaskOption.zip left right 22 | // task { Some (123, "abc") } 23 | ``` 24 | 25 | ### Example 2 26 | 27 | ```fsharp 28 | let left = TaskOption.some 123 29 | let right = TaskOption.singleton None 30 | 31 | TaskOption.zip left right 32 | // task { None } 33 | ``` 34 | -------------------------------------------------------------------------------- /gitbook/taskResult/apply.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task 'b), 'c>> 9 | -> Task> 10 | -> Task> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/taskResult/bind.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Task>) 9 | -> Task> 10 | -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` operations can also be solved using [the `taskResult` computation expression](../taskResult/ce.md). 16 | 17 | ### Example 1 18 | 19 | Continuing from the [TaskResult.map2 example](../taskResult/map2.md#example-1) and given the function 20 | 21 | ```fsharp 22 | let notifyFollowers : NotifyNewPostRequest -> Task> 23 | ``` 24 | 25 | we can notify all followers using `TaskResult.bind` as below: 26 | 27 | ```fsharp 28 | newPostRequestResult |> TaskResult.bind notifyFollowers 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/taskResult/catch.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.catch 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Catches exceptions and maps them to the Error case using the provided function. 6 | 7 | Function Signature: 8 | 9 | ```fsharp 10 | (exn -> 'a) -> Task> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Given the function: 16 | 17 | ```fsharp 18 | let taskThrow () = 19 | task { 20 | failwith "an exception happened" 21 | return Error "" 22 | } 23 | ``` 24 | 25 | ### Example 1 26 | 27 | ```fsharp 28 | let result : Task> = TaskResult.catch (_.Message) (TaskResult.ok 42) 29 | // task { Ok 42 } 30 | ``` 31 | 32 | ### Example 2 33 | 34 | ```fsharp 35 | let result : Task> = TaskResult.catch (_.Message) (TaskResult.error "something bad happened") 36 | // task { Error "something bad happened" } 37 | ``` 38 | 39 | ### Example 3 40 | 41 | ```fsharp 42 | let result : Task> = TaskResult.catch (_.Message) (taskThrow ()) 43 | // task { Error "an exception happened" } 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /gitbook/taskResult/ce.md: -------------------------------------------------------------------------------- 1 | ## TaskResult Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | 6 | ## Examples 7 | 8 | ### Example 1 9 | 10 | The initial [motivating example](../README.md) is perhaps more realistic if some functions are asynchronous. Given the following functions: 11 | 12 | ```fsharp 13 | tryGetUser : string -> Task 14 | isPwdValid : string -> User -> bool 15 | authorize : User -> Task> 16 | createAuthToken : User -> Result 17 | ``` 18 | 19 | A login flow can be implemented as below using the `taskResult` CE and a few [helpers](others.md): 20 | 21 | ```fsharp 22 | type LoginError = 23 | | InvalidUser 24 | | InvalidPwd 25 | | Unauthorized of AuthError 26 | | TokenErr of TokenError 27 | 28 | let login (username: string) (password: string) : Task> = 29 | taskResult { 30 | let! user = username |> tryGetUser |> TaskResult.requireSome InvalidUser 31 | do! user |> isPwdValid password |> Result.requireTrue InvalidPwd 32 | do! user |> authorize |> TaskResult.mapError Unauthorized 33 | return! user |> createAuthToken |> Result.mapError TokenErr 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /gitbook/taskResult/error.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Task>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Task> = 20 | TaskResult.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/taskResult/foldResult.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.foldResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> ('c -> 'b) -> Task> -> Task<'b> 9 | ``` 10 | 11 | This is just a shortcut for `Task.map Result.fold`. See [Result.fold](../result/fold.md) for more. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | type HttpResponse<'a, 'b> = 19 | | Ok of 'a 20 | | InternalError of 'b 21 | 22 | // CreatePostRequest -> Task> 23 | let createPost (req : CreatePostRequest) = task { 24 | // ... 25 | } 26 | 27 | // Task 28 | let handler (httpReq : HttpRequest) = 29 | // ... 30 | 31 | // Task> 32 | let createPostTR = createPost httpReq 33 | 34 | createPostTR 35 | |> TaskResult.fold Ok InternalError 36 | ``` 37 | -------------------------------------------------------------------------------- /gitbook/taskResult/ignore.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task> -> Task> 9 | ``` 10 | 11 | This is a shortcut for `TaskResult.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let savePost : CreatePostRequest -> Task> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `TaskResult.ignore` as below: 22 | 23 | ```fsharp 24 | let makePost = taskResult { 25 | do! savePost createPostRequest |> TaskResult.ignore 26 | } 27 | ``` -------------------------------------------------------------------------------- /gitbook/taskResult/map.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Task> -> Task> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Note: Many use-cases requiring `map` operations can also be solved using [the `taskResult` computation expression](../taskResult/ce.md). 14 | 15 | ### Example 1 16 | 17 | As a continuation of [Result.map3 Example 2](../result/map3.md#example-2), let's assume that we want to store the created post in the database using the function 18 | 19 | ```fsharp 20 | savePost : CreatePostRequest -> Task> 21 | ``` 22 | 23 | We can save the post and return its inner using `TaskResult.map`: 24 | 25 | ```fsharp 26 | let rawPostId : Task> = 27 | savePost createPostRequest 28 | |> TaskResult.map (fun (PostId postId) -> postId) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/taskResult/map3.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Task> 10 | -> Task> 11 | -> Task> 12 | -> Task> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `taskResult` computation expression](../taskResult/ce.md). -------------------------------------------------------------------------------- /gitbook/taskResult/mapError.md: -------------------------------------------------------------------------------- 1 | ## TaskResult.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Task> -> Task> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | From the [TaskResult.map](../taskResult/map.md#example-1) example, if we want to map the error part alone, we can do it as below: 16 | 17 | ```fsharp 18 | // Task, string> 19 | createPost createPostRequest 20 | |> TaskResult.mapError (fun (ex : exn) -> ex.Message) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/taskResult/ofAsync.md: -------------------------------------------------------------------------------- 1 | # TaskResult.ofAsync 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms an `Async<'T>` into a `Task>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Async<'T> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = TaskResult.ofAsync (async { return 42 }) 19 | // task { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = TaskResult.ofAsync (async { return System.Exception("error") }) 26 | // task { return Error (System.Exception("error")) } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskResult/ofResult.md: -------------------------------------------------------------------------------- 1 | # TaskResult.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into a `Task>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = TaskResult.ofResult (Ok 42) 19 | // task { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = TaskResult.ofResult (Error "error") 26 | // task { return Error "error" } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskResult/ofTask.md: -------------------------------------------------------------------------------- 1 | # TaskResult.ofTask 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Task<'T>` into a `Task>`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'T> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = TaskResult.ofTask (task { return 42 }) 19 | // task { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = TaskResult.ofTask (task { return System.Exception("error") }) 26 | // task { return Error (System.Exception("error")) } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskResult/operators.md: -------------------------------------------------------------------------------- 1 | ## TaskResult Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.TaskResult` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `Task>` type. 6 | 7 | ## Examples: 8 | 9 | ### Example 1 10 | 11 | Expanding on the [TaskResult.map2 example](../taskResult/map2.md#example-1), we define another function: 12 | 13 | ```fsharp 14 | notifyFollowers : NotifyNewPostRequest -> Task> 15 | ``` 16 | 17 | We can then rewrite the example and additionally call `notifyFollowers` using the operators as below: 18 | 19 | ```fsharp 20 | open FsToolkit.ErrorHandling.Operator.TaskResult 21 | 22 | // CreatePostRequest -> Task> 23 | let createPostAndNotifyFollowers (req : CreatePostRequest) = 24 | notifyNewPostRequest 25 | (getFollowerIds req.UserId) 26 | <*> (createPost req) 27 | >>= notifyFollowers 28 | ``` 29 | -------------------------------------------------------------------------------- /gitbook/taskResult/zip.md: -------------------------------------------------------------------------------- 1 | # TaskResult.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Task> -> Task> -> Task> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = TaskResult.zip (TaskResult.ok 1) (TaskResult.ok 2) 17 | // task { Ok (1, 2) } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = TaskResult.zip (TaskResult.ok 1) (TaskResult.error "Bad") 24 | // task { Error "Bad" } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = TaskResult.zip (TaskResult.error "Bad1") (TaskResult.error "Bad2") 31 | // task { Error "Bad1" } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/taskResult/zipError.md: -------------------------------------------------------------------------------- 1 | # TaskResult.zipError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Task> -> Task> -> Task> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = TaskResult.zipError (TaskResult.ok 1) (TaskResult.ok 2) 17 | // task { Ok 1 } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = TaskResult.zipError (TaskResult.ok 1) (TaskResult.error "Bad") 24 | // task { Ok 1 } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = TaskResult.zipError (TaskResult.error "Bad1") (TaskResult.error "Bad2") 31 | // task { Error("Bad1", "Bad2") } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/apply.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task 'b) option, 'c>> 9 | -> Task> 10 | -> Task> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/bind.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.bind 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> Task>) 9 | -> Task> 10 | -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Note: Many use-cases requiring `bind` can also be solved using [the `taskResultOption` computation expression](ce.md). 16 | 17 | ### Example 1 18 | 19 | Given the following functions: 20 | 21 | ```fsharp 22 | getUserById : UserId -> Task> 23 | getPostById : PostId -> Task> 24 | ``` 25 | 26 | We can get a post's user given a `PostId` like this: 27 | 28 | ```fsharp 29 | // Task> 30 | getPostById postId 31 | |> TaskResultOption.bind (fun post -> getUserById post.UserId) 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/ce.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples 6 | 7 | ### Example 1 8 | 9 | The [TaskResultOption.map2 example](../taskResultOption/map2.md#example-1) can be written using the `taskResultOption` computation expression as below: 10 | 11 | ```fsharp 12 | // Task> 13 | taskResultOption { 14 | let! post = getPostById samplePostId 15 | let! user = getUserById post.UserId 16 | return userTweet post user 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/error.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Task>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Task> = 20 | TaskResultOption.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/ignore.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.ignore 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task> -> Task> 9 | ``` 10 | 11 | This is a shortcut for `TaskResultOption.map ignore`. 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let deletePostIfExists : DeletePostRequest -> Task> 19 | ``` 20 | 21 | We can call this with the `do!` syntax inside a computation expression using `TaskResultOption.ignore` as below: 22 | 23 | ```fsharp 24 | let deletePost = taskResultOption { 25 | do! deletePostIfExists deletePostRequest |> TaskResultOption.ignore 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/map.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b) -> Task> 9 | -> Task> 10 | ``` 11 | 12 | ## Examples 13 | 14 | Note: Many use-cases requiring `map` operations can also be solved using [the `taskResultOption` computation expression](ce.md). 15 | 16 | ### Example 1 17 | 18 | Given the function 19 | 20 | ```fsharp 21 | getUserById : UserId -> Task> 22 | ``` 23 | 24 | Then using the `TaskResultOption.map` we can get the name of the user like this: 25 | 26 | ```fsharp 27 | // Task, exn> 28 | getUserById sampleUserId 29 | |> TaskResultOption.map (fun user -> user.Name) 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/map2.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Task> 10 | -> Task> 11 | -> Task> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Note: Many use-cases requiring `map` operations can also be solved using [the `taskResultOption` computation expression](ce.md). 17 | 18 | ### Example 1 19 | 20 | Given the following functions: 21 | 22 | ```fsharp 23 | getPostById : PostId -> Task> 24 | getUserById : UserId -> Task> 25 | userTweet : Post -> User -> UserTweet 26 | ``` 27 | 28 | Then given a `PostId` and a `UserId`, we can call `userTweet` like this: 29 | 30 | ```fsharp 31 | // Task> 32 | TaskResultOption.map2 userTweet (getPostById postId) (getUserById userId) 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/map3.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Task> 10 | -> Task> 11 | -> Task> 12 | -> Task> 13 | ``` 14 | 15 | ## Examples 16 | 17 | Note: Many use-cases requiring `map` operations can also be solved using [the `taskResultOption` computation expression](ce.md). 18 | -------------------------------------------------------------------------------- /gitbook/taskResultOption/operators.md: -------------------------------------------------------------------------------- 1 | ## TaskResultOption Infix Operators 2 | 3 | Namespace: `FsToolkit.ErrorHandling.Operator.TaskResultOption` 4 | 5 | FsToolkit.ErrorHandling provides the standard infix operators for the `map` (``), `apply` (`<*>`), and `bind` (`>>=`) functions of the `Result,_>` type. 6 | 7 | ## Examples 8 | 9 | ### Example 1 10 | 11 | The [TaskResultOption map2 example](../taskResultOption/map2.md#example-1) can be written using operators like this: 12 | 13 | ```fsharp 14 | open FsToolkit.ErrorHandling.Operator.TaskResult 15 | 16 | // Task> 17 | userTweet 18 | (getPostById samplePostId) 19 | <*> (getUserById sampleUserId) 20 | ``` 21 | -------------------------------------------------------------------------------- /gitbook/taskValidation/apply.md: -------------------------------------------------------------------------------- 1 | ## TaskValidation.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task 'b), 'c list>> 9 | -> Task> 10 | -> Task> 11 | ``` 12 | 13 | ## Examples 14 | -------------------------------------------------------------------------------- /gitbook/taskValidation/ce.md: -------------------------------------------------------------------------------- 1 | ## TaskValidation Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | The `TaskValidation` type is defined as: 6 | 7 | ```fsharp 8 | type TaskValidation<'a,'err> = Task> 9 | ``` 10 | 11 | This CE can take advantage of the [and! operator](https://github.com/fsharp/fslang-suggestions/issues/579) to join multiple error results into a list. 12 | 13 | ## Examples 14 | 15 | See [here](../validation/ce.md) for other validation-like examples 16 | 17 | ```fsharp 18 | // Result -> Task> 19 | let downloadTask stuff = task { 20 | return stuff 21 | } 22 | 23 | // TaskValidation 24 | let addResult = taskValidation { 25 | let! x = downloadTask (Ok "I") 26 | and! y = downloadTask (Ok "am") 27 | and! z = downloadTask (Ok "async!") 28 | return sprintf "%s %s %s" x y z 29 | } 30 | // task { return Ok "I am async!" } 31 | 32 | // TaskValidation 33 | let addResult = taskValidation { 34 | let! x = downloadTask (Error "Am") 35 | and! y = downloadTask (Error "I") 36 | and! z = downloadTask (Error "async?") 37 | return sprintf "%s %s %s" x y z 38 | } 39 | 40 | // task { return Error [ "Am"; "I"; "async?" ] } 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/taskValidation/error.md: -------------------------------------------------------------------------------- 1 | ## TaskValidation.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Task>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Task> = 20 | TaskValidation.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/taskValidation/index.md: -------------------------------------------------------------------------------- 1 | # TaskValidation 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This module provides utility functions and infix operators to work with `Task>`. 6 | -------------------------------------------------------------------------------- /gitbook/taskValidation/map2.md: -------------------------------------------------------------------------------- 1 | ## TaskValidation.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Task> 10 | -> Task> 11 | -> Task> 12 | ``` 13 | 14 | Like [Result.map2](../result/map2.md), but collects the errors from both arguments. 15 | 16 | ## Examples 17 | -------------------------------------------------------------------------------- /gitbook/taskValidation/map3.md: -------------------------------------------------------------------------------- 1 | ## TaskValidation.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Task> 10 | -> Task> 11 | -> Task> 12 | -> Task> 13 | ``` 14 | 15 | Like [Result.map3](../result/map3.md), but collects the errors from all arguments. 16 | 17 | ## Examples 18 | -------------------------------------------------------------------------------- /gitbook/taskValidation/mapError.md: -------------------------------------------------------------------------------- 1 | # TaskValidation.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `mapError` takes an task validation and a normal function and returns a new task validation value based on the input error value and the function 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput -> 'errorOutput) -> TaskValidation<'ok, 'errorInput> 11 | -> TaskValidation<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (message: string) = 21 | match message with 22 | | "bad things happened" -> 1 23 | | _ -> 0 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | TaskValidation.ok "all good" // TaskValidation 31 | |> TaskValidation.mapError getErrorCode // TaskValidation 32 | 33 | // task { Ok "all good" } 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result = 40 | TaskValidation.error "bad things happened" // TaskValidation 41 | |> TaskValidation.mapError getErrorCode // TaskValidation 42 | 43 | // task { Error [1] } 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/taskValidation/mapErrors.md: -------------------------------------------------------------------------------- 1 | # TaskValidation.mapErrors 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Similar to [TaskValidation.mapError](../taskValidation/mapError.md), except that the mapping function is passed the full list of errors, rather than each one individually. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput list -> 'errorOutput list) -> TaskValidation<'ok, 'errorInput> 11 | -> TaskValidation<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (messages: string list) = 21 | match messages |> List.tryFind ((=) "bad things happened") with 22 | | Some _ -> [1] 23 | | _ -> [0] 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | TaskValidation.ok "all good" // TaskValidation 31 | |> TaskValidation.mapErrors getErrorCode // TaskValidation 32 | 33 | // task { Ok "all good" } 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result : TaskValidation = 40 | TaskValidation.error "bad things happened" // TaskValidation 41 | |> TaskValidation.mapErrors getErrorCode // TaskValidation 42 | 43 | // task { Error [1] } 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/taskValidation/ofChoice.md: -------------------------------------------------------------------------------- 1 | # TaskValidation.ofChoice 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Choice<'T, 'Error>` into a `Task>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'T, 'Error> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = TaskValidation.ofChoice (Choice1Of2 42) 19 | // task { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = TaskValidation.ofChoice (Choice2Of2 "error") 26 | // task { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskValidation/ofResult.md: -------------------------------------------------------------------------------- 1 | # TaskValidation.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into a `Task>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Task> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = TaskValidation.ofResult (Ok 42) 19 | // task { return Ok 42 } 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = TaskValidation.ofResult (Error "error") 26 | // task { return Error ["error"] } 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/taskValidation/zip.md: -------------------------------------------------------------------------------- 1 | # TaskValidation.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | TaskValidation<'leftOk, 'error> -> TaskValidation<'rightOk, 'error> -> TaskValidation<'leftOk * 'rightOk, 'error> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = TaskValidation.zip (TaskValidation.ok 1) (TaskValidation.ok 2) 17 | // task { Ok (1, 2) } 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = TaskValidation.zip (TaskValidation.ok 1) (TaskValidation.error "Bad") 24 | // task { Error [ "Bad" ] } 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = TaskValidation.zip (TaskValidation.error "Bad1") (TaskValidation.error "Bad2") 31 | // task { Error [ "Bad1"; "Bad2" ] } 32 | ``` 33 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/apply.md: -------------------------------------------------------------------------------- 1 | # TaskValueOption.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Task<('a -> 'b) voption> -> Task<'a voption> -> Task<'b voption> 9 | ``` 10 | 11 | ## Examples 12 | 13 | Take the following function for example 14 | 15 | ```fsharp 16 | // string -> int 17 | let characterCount (s: string) = s.Length 18 | ``` 19 | 20 | ### Example 1 21 | 22 | ```fsharp 23 | let result = 24 | TaskValueOption.valueSome "foo" // Task 25 | |> TaskValueOption.apply (TaskValueOption.valueSome characterCount) // Task 26 | 27 | // task { ValueSome 3 } 28 | ``` 29 | 30 | ### Example 2 31 | 32 | ```fsharp 33 | let result = 34 | Task.singleton ValueNone // Task 35 | |> TaskValueOption.apply (TaskValueOption.valueSome characterCount) // Task 36 | 37 | // task { ValueNone } 38 | ``` 39 | 40 | ### Example 3 41 | 42 | ```fsharp 43 | let result : Task = 44 | TaskValueOption.valueSome "foo" // Task 45 | |> TaskValueOption.apply (Task.singleton ValueNone) // Task 46 | 47 | // task { ValueNone } 48 | ``` 49 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/ce.md: -------------------------------------------------------------------------------- 1 | ## TaskValueOption Computation Expression 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Examples: 6 | 7 | ### Example 1 8 | 9 | Given a personId and an age, find a person and update their age. 10 | 11 | ```fsharp 12 | tryParseInt : string -> int voption 13 | tryFindPersonById : int -> Task 14 | updatePerson : Person -> Task 15 | ``` 16 | 17 | ```fsharp 18 | // Task 19 | let addResult = taskValueOption { 20 | let! personId = tryParseInt "3001" 21 | let! age = tryParseInt "35" 22 | let! person = tryFindPersonById personId 23 | let person = { person with Age = age } 24 | do! updatePerson person 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/either.md: -------------------------------------------------------------------------------- 1 | # TaskValueOption.either 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | Provide two functions to execute depending on the value of the voption. If the voption is `ValueSome`, the first function will be executed. If the voption is `ValueNone`, the second function will be executed. 8 | 9 | ```fsharp 10 | (onValueSome : 'T -> Task<'output>) 11 | -> (onValueNone : Task<'output>) 12 | -> (input : Task<'T voption>) 13 | -> Task<'output> 14 | ``` 15 | 16 | ## Examples 17 | 18 | ### Example 1 19 | 20 | ```fsharp 21 | TaskValueOption.either (fun x -> task { x * 2 }) (task { 0 }) (TaskValueOption.valueSome 5) 22 | 23 | // task { 10 } 24 | ``` 25 | 26 | ### Example 2 27 | 28 | ```fsharp 29 | TaskValueOption.either (fun x -> task { x * 2 }) (task { 0 }) ValueNone 30 | 31 | // task { 0 } 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/map.md: -------------------------------------------------------------------------------- 1 | # TaskValueOption.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Apply a function to the value of a task voption if it is `ValueSome`. If the option is `ValueNone`, return `ValueNone`. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('input -> 'output) -> Task<'input voption> -> Task<'output voption> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | TaskValueOption.map (fun x -> x + 1) (TaskValueOption.valueSome 1) 19 | 20 | // task { ValueSome 2 } 21 | ``` 22 | 23 | ### Example 2 24 | 25 | ```fsharp 26 | TaskValueOption.map (fun x -> x + 1) (Task.singleton ValueNone) 27 | 28 | // task { ValueNone } 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/others.md: -------------------------------------------------------------------------------- 1 | # Other TaskValueOption Functions 2 | 3 | ## defaultValue 4 | 5 | Returns the contained value if ValueSome, otherwise returns the provided value 6 | 7 | ### Function Signature 8 | 9 | ```fsharp 10 | 'a -> Task<'a voption> -> Task<'a> 11 | ``` 12 | 13 | ## defaultWith 14 | 15 | Returns the contained value if ValueSome, otherwise evaluates the given function and returns the result. 16 | 17 | ### Function Signature 18 | 19 | ```fsharp 20 | (unit -> 'a) -> Task<'a voption> -> Task<'a> 21 | ``` 22 | 23 | ## valueSome 24 | 25 | Wraps the provided value in an Task<'a voption> 26 | 27 | ### Function Signature 28 | 29 | ```fsharp 30 | 'a -> Task<'a voption> 31 | ``` 32 | 33 | 34 | -------------------------------------------------------------------------------- /gitbook/taskValueOption/zip.md: -------------------------------------------------------------------------------- 1 | # TaskValueOption.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Takes two voptions and returns a tuple of the pair or ValueNone if either are ValueNone 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Task<'left voption> -> Task<'right voption> -> Task<('left * 'right) voption> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let left = TaskValueOption.valueSome 123 19 | let right = TaskValueOption.valueSome "abc" 20 | 21 | TaskValueOption.zip left right 22 | // task { ValueSome (123, "abc") } 23 | ``` 24 | 25 | ### Example 2 26 | 27 | ```fsharp 28 | let left = TaskValueOption.valueSome 123 29 | let right = Task.singleton ValueNone 30 | 31 | TaskValueOption.zip left right 32 | // task { ValueNone } 33 | ``` 34 | -------------------------------------------------------------------------------- /gitbook/test/index.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demystifyfp/FsToolkit.ErrorHandling/47f197db5940fc56ca90cab29afd6801aa09d7c1/gitbook/test/index.md -------------------------------------------------------------------------------- /gitbook/test/testing-nested1.md: -------------------------------------------------------------------------------- 1 | # testing nested 1 -------------------------------------------------------------------------------- /gitbook/test/testing-nested2.md: -------------------------------------------------------------------------------- 1 | # testing nested 2 -------------------------------------------------------------------------------- /gitbook/validation/apply.md: -------------------------------------------------------------------------------- 1 | ## Validation.apply 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | Result<('a -> 'b), 'c list> 9 | -> Result<'a, 'c list> 10 | -> Result<'b, 'c list> 11 | ``` 12 | 13 | ## Examples -------------------------------------------------------------------------------- /gitbook/validation/error.md: -------------------------------------------------------------------------------- 1 | ## Validation.error 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Lift an `'error` value into an `Validation<'ok, 'error>` 6 | 7 | ## Function Signature: 8 | 9 | ```fsharp 10 | 'error -> Validation<'ok, 'error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | 18 | ```fsharp 19 | let result : Validation = 20 | Validation.error "Something bad happened" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /gitbook/validation/index.md: -------------------------------------------------------------------------------- 1 | # Validation 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | This module provides utility functions and infix operators to work with `Result<'a, 'b list>`. 6 | -------------------------------------------------------------------------------- /gitbook/validation/map.md: -------------------------------------------------------------------------------- 1 | # Validation.map 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `map` applies a transformation to the value inside a `Validation` if it represents a successful result (`Ok`). It allows you to perform a computation on the value while preserving the success/error status of the original `Validation`. If the original `Validation` is an `Error`, `map` does nothing and returns the same `Error` unchanged. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('okInput -> 'okOutput) -> Validation<'okInput, 'error> -> Validation<'okOutput, 'error> 11 | ``` 12 | 13 | ## Examples 14 | 15 | Take the following functions for example 16 | 17 | ```fsharp 18 | // string -> int 19 | let remainingCharacters (prompt: string) = 20 | 280 - prompt.Length 21 | ``` 22 | 23 | ### Example 1 24 | 25 | ```fsharp 26 | let validation = 27 | Validation.ok "foo" // Validation 28 | |> Validation.map remainingCharacters // Validation 29 | 30 | // Ok 277 31 | ``` 32 | 33 | ### Example 2 34 | 35 | ```fsharp 36 | let result = 37 | Validation.error "bad things happened" // Validation 38 | |> Validation.map remainingCharacters // Validation 39 | 40 | // Error ["bad things happened"] 41 | ``` 42 | -------------------------------------------------------------------------------- /gitbook/validation/map2.md: -------------------------------------------------------------------------------- 1 | ## Validation.map2 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ```fsharp 8 | ('a -> 'b -> 'c) 9 | -> Result<'a, 'd list> 10 | -> Result<'b, 'd list> 11 | -> Result<'c, 'd list> 12 | ``` 13 | 14 | Like [Result.map2](../result/map2.md), but collects the errors from both arguments. 15 | 16 | ## Examples -------------------------------------------------------------------------------- /gitbook/validation/map3.md: -------------------------------------------------------------------------------- 1 | ## Validation.map3 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Function Signature: 6 | 7 | ``` 8 | ('a -> 'b -> 'c -> 'd) 9 | -> Result<'a, 'e list> 10 | -> Result<'b, 'e list> 11 | -> Result<'c, 'e list> 12 | -> Result<'d, 'e list> 13 | ``` 14 | 15 | Like [Result.map3](../result/map3.md), but collects the errors from all arguments. 16 | 17 | ## Examples 18 | -------------------------------------------------------------------------------- /gitbook/validation/mapError.md: -------------------------------------------------------------------------------- 1 | # Validation.mapError 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | `mapError` takes a validation and a normal function and returns a new validation value based on the input error value and the function 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput -> 'errorOutput) -> Validation<'ok, 'errorInput> 11 | -> Validation<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (message: string) = 21 | match message with 22 | | "bad things happened" -> 1 23 | | _ -> 0 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | Validation.ok "all good" // Validation 31 | |> Validation.mapError getErrorCode // Validation 32 | 33 | // Ok "all good" 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result = 40 | Validation.error "bad things happened" // Validation 41 | |> Validation.mapError getErrorCode // Validation 42 | 43 | // Error [1] 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/validation/mapErrors.md: -------------------------------------------------------------------------------- 1 | # Validation.mapErrors 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Similar to [Validation.mapError](../validation/mapError.md), except that the mapping function is passed the full list of errors, rather than each one individually. 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | ('errorInput list -> 'errorOutput list) -> Validation<'ok, 'errorInput> 11 | -> Validation<'ok, 'errorOutput> 12 | ``` 13 | 14 | ## Examples 15 | 16 | Take the following functions for example 17 | 18 | ```fsharp 19 | // string -> int 20 | let getErrorCode (messages: string list) = 21 | match messages |> List.tryFind ((=) "bad things happened") with 22 | | Some _ -> [1] 23 | | _ -> [0] 24 | ``` 25 | 26 | ### Example 1 27 | 28 | ```fsharp 29 | let result = 30 | Validation.ok "all good" // Validation 31 | |> Validation.mapErrors getErrorCode // Validation 32 | 33 | // Ok "all good" 34 | ``` 35 | 36 | ### Example 2 37 | 38 | ```fsharp 39 | let result : Validation = 40 | Validation.error "bad things happened" // Validation 41 | |> Validation.mapErrors getErrorCode // Validation 42 | 43 | // Error [1] 44 | ``` 45 | -------------------------------------------------------------------------------- /gitbook/validation/ofChoice.md: -------------------------------------------------------------------------------- 1 | # Validation.ofChoice 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Choice<'T, 'Error>` into a `Result<'T, 'Error list>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Choice<'T, 'Error> -> Result<'T, 'Error list> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = Validation.ofChoice (Choice1Of2 42) 19 | // Ok 42 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = Validation.ofChoice (Choice2Of2 "error") 26 | // Error ["error"] 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/validation/ofResult.md: -------------------------------------------------------------------------------- 1 | # Validation.ofResult 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | Transforms a `Result<'T, 'Error>` into a `Result<'T, 'Error list>` 6 | 7 | ## Function Signature 8 | 9 | ```fsharp 10 | Result<'T, 'Error> -> Result<'T, 'Error list> 11 | ``` 12 | 13 | ## Examples 14 | 15 | ### Example 1 16 | 17 | ```fsharp 18 | let result = Validation.ofResult (Ok 42) 19 | // Ok 42 20 | ``` 21 | 22 | ### Example 2 23 | 24 | ```fsharp 25 | let result = Validation.ofResult (Error "error") 26 | // Error ["error"] 27 | ``` 28 | -------------------------------------------------------------------------------- /gitbook/validation/zip.md: -------------------------------------------------------------------------------- 1 | # Validation.zip 2 | 3 | Namespace: `FsToolkit.ErrorHandling` 4 | 5 | ## Function Signature 6 | 7 | ```fsharp 8 | Validation<'leftOk, 'error> -> Validation<'rightOk, 'error> -> Validation<'leftOk * 'rightOk, 'error> 9 | ``` 10 | 11 | ## Examples 12 | 13 | ### Example 1 14 | 15 | ```fsharp 16 | let result = Validation.zip (Validation.ok 1) (Validation.ok 2) 17 | // Ok (1, 2) 18 | ``` 19 | 20 | ### Example 2 21 | 22 | ```fsharp 23 | let result = Validation.zip (Validation.ok 1) (Validation.error "Bad") 24 | // Error [ "Bad" ] 25 | ``` 26 | 27 | ### Example 3 28 | 29 | ```fsharp 30 | let result = Validation.zip (Validation.error "Bad1") (Validation.error "Bad2") 31 | // Error [ "Bad1"; "Bad2" ] 32 | ``` 33 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "9.0.100", 4 | "rollForward": "latestMinor" 5 | } 6 | } -------------------------------------------------------------------------------- /msbuild.binlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/demystifyfp/FsToolkit.ErrorHandling/47f197db5940fc56ca90cab29afd6801aa09d7c1/msbuild.binlog -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.AsyncSeq/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.AsyncSeq" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.AsyncSeq/FsToolkit.ErrorHandling.AsyncSeq.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | netstandard2.1;netstandard2.0;net9.0 6 | portable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.IcedTasks/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.IcedTasks" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | net6.0;netstandard2.0;netstandard2.1;net9.0 6 | 7 | portable 8 | $(NoWarn);FS3511;FS3513 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.JobResult" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/Job.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling 2 | 3 | open Hopac 4 | open Hopac.Infixes 5 | 6 | [] 7 | module Job = 8 | let inline singleton x = Job.result x 9 | let inline apply' x f = Job.apply f x 10 | let inline map2 ([] f) x y = (apply' (apply' (singleton f) x) y) 11 | 12 | let inline map3 ([] f) x y z = apply' (map2 f x y) z 13 | 14 | let inline zip j1 j2 = j1 <&> j2 15 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/JobOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.JobOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module JobOption = 7 | 8 | let inline () ([] f) x = JobOption.map f x 9 | let inline (<*>) f x = JobOption.apply f x 10 | let inline (>>=) x ([] f) = JobOption.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/JobResultOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.JobResult 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module JobResult = 7 | 8 | let inline () ([] f) x = JobResult.map f x 9 | let inline (<*>) f x = JobResult.apply f x 10 | let inline (>>=) x ([] f) = JobResult.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/JobResultOption.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling 2 | 3 | [] 4 | module JobResultOption = 5 | open Hopac 6 | let inline map ([] f) jro = JobResult.map (Option.map f) jro 7 | 8 | let inline bind ([] f) jro = 9 | let binder opt = 10 | match opt with 11 | | Some x -> f x 12 | | None -> JobResult.singleton None 13 | 14 | JobResult.bind binder jro 15 | 16 | let inline map2 ([] f) xJRO yJRO = 17 | JobResult.map2 (Option.map2 f) xJRO yJRO 18 | 19 | let inline map3 ([] f) xJRO yJRO zJRO = 20 | JobResult.map3 (Option.map3 f) xJRO yJRO zJRO 21 | 22 | let inline singleton value = 23 | Some value 24 | |> Ok 25 | |> Job.result 26 | 27 | let apply fJRO xJRO = map2 (fun f x -> f x) fJRO xJRO 28 | 29 | /// Replaces the wrapped value with unit 30 | let inline ignore<'a, 'b> (jro: Job>) = 31 | jro 32 | |> map ignore<'a> 33 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/JobResultOptionCE.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling 2 | 3 | [] 4 | module JobResultOptionCE = 5 | open Hopac 6 | 7 | type JobResultOptionBuilder() = 8 | member inline _.Return value = JobResultOption.singleton value 9 | member inline _.ReturnFrom value = value 10 | member inline _.Bind(result, [] binder) = JobResultOption.bind binder result 11 | 12 | member inline _.Combine(aro1, aro2) = 13 | aro1 14 | |> JobResultOption.bind (fun _ -> aro2) 15 | 16 | member inline _.Delay([] f) = Job.delay f 17 | 18 | let jobResultOption = new JobResultOptionBuilder() 19 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/JobResultOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.JobResultOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module JobResultOption = 7 | 8 | let inline () ([] f) x = JobResultOption.map f x 9 | let inline (<*>) f x = JobResultOption.apply f x 10 | let inline (>>=) x ([] f) = JobResultOption.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling.JobResult/Result.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling 2 | 3 | open Hopac 4 | 5 | module Result = 6 | 7 | let sequenceJob (resJob: Result, 'b>) : Job> = 8 | job { 9 | match resJob with 10 | | Ok job -> 11 | let! x = job 12 | return Ok x 13 | | Error err -> return Error err 14 | } 15 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/AsyncOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.AsyncOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module AsyncOption = 7 | 8 | let inline () 9 | (([] mapper: 'input -> 'output)) 10 | (input: Async<'input option>) 11 | : Async<'output option> = 12 | AsyncOption.map mapper input 13 | 14 | let inline (<*>) 15 | (applier: Async<('input -> 'output) option>) 16 | (input: Async<'input option>) 17 | : Async<'output option> = 18 | AsyncOption.apply applier input 19 | 20 | let inline (>>=) 21 | (input: Async<'input option>) 22 | ([] binder: 'input -> Async<'output option>) 23 | : Async<'output option> = 24 | AsyncOption.bind binder input 25 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/AsyncResultOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.AsyncResult 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module AsyncResult = 7 | 8 | let inline () 9 | (([] mapper: 'okInput -> 'okOutput)) 10 | (input: Async>) 11 | : Async> = 12 | AsyncResult.map mapper input 13 | 14 | let inline (<*>) 15 | (applier: Async 'okOutput, 'error>>) 16 | (input: Async>) 17 | : Async> = 18 | AsyncResult.apply applier input 19 | 20 | let inline (>>=) 21 | (input: Async>) 22 | ([] binder: 'input -> Async>) 23 | : Async> = 24 | AsyncResult.bind binder input 25 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/AsyncResultOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.AsyncResultOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module AsyncResultOption = 7 | 8 | let inline () 9 | ([] mapper: 'okInput -> 'okOutput) 10 | (input: Async>) 11 | : Async> = 12 | AsyncResultOption.map mapper input 13 | 14 | let inline (<*>) 15 | (applier: Async 'okOutput) option, 'error>>) 16 | (input: Async>) 17 | : Async> = 18 | AsyncResultOption.apply applier input 19 | 20 | let inline (>>=) 21 | (input: Async>) 22 | ([] binder: 'okInput -> Async>) 23 | : Async> = 24 | AsyncResultOption.bind binder input 25 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/OptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.Option 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | /// 6 | /// Operators for working with the Option type. 7 | /// 8 | [] 9 | module Option = 10 | 11 | /// 12 | /// Shorthand for Option.map 13 | /// 14 | /// The Option value to bind over. 15 | /// The function to bind over the Option value. 16 | /// The result of binding the function over the Option value. 17 | let inline (>>=) 18 | (input: Option<'input>) 19 | ([] binder: 'input -> Option<'output>) 20 | : Option<'output> = 21 | Option.bind binder input 22 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.Task 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module Task = 7 | let inline () ([] f) x = Task.map f x 8 | let inline (<*>) f x = Task.apply f x 9 | let inline (>>=) x ([] f) = Task.bind f x 10 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.TaskOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module TaskOption = 7 | 8 | let inline () ([] f) x = TaskOption.map f x 9 | let inline (<*>) f x = TaskOption.apply f x 10 | let inline (>>=) x ([] f) = TaskOption.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskResultOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.TaskResult 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module TaskResult = 7 | 8 | let inline () ([] f) x = TaskResult.map f x 9 | let inline (<*>) f x = TaskResult.apply f x 10 | let inline (>>=) x ([] f) = TaskResult.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskResultOption.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling 2 | 3 | open System.Threading.Tasks 4 | 5 | 6 | [] 7 | module TaskResultOption = 8 | let inline map ([] f) tro = TaskResult.map (Option.map f) tro 9 | 10 | let inline bind ([] f) tro = 11 | let binder opt = 12 | match opt with 13 | | Some x -> f x 14 | | None -> TaskResult.ok None 15 | 16 | TaskResult.bind binder tro 17 | 18 | let inline map2 ([] f) xTRO yTRO = 19 | TaskResult.map2 (Option.map2 f) xTRO yTRO 20 | 21 | let inline map3 ([] f) xTRO yTRO zTRO = 22 | TaskResult.map3 (Option.map3 f) xTRO yTRO zTRO 23 | 24 | let inline singleton value = TaskResult.ok (Some value) 25 | 26 | let inline ok x = singleton x 27 | 28 | let inline error x : TaskResult<'ok option, 'error> = TaskResult.error x 29 | 30 | let inline apply fTRO xTRO = map2 (fun f x -> f x) fTRO xTRO 31 | 32 | /// Replaces the wrapped value with unit 33 | let inline ignore<'ok, 'error> (tro: Task>) = 34 | tro 35 | |> map ignore<'ok> 36 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskResultOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.TaskResultOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module TaskResultOption = 7 | 8 | let inline () ([] f) x = TaskResultOption.map f x 9 | let inline (<*>) f x = TaskResultOption.apply f x 10 | let inline (>>=) x ([] f) = TaskResultOption.bind f x 11 | -------------------------------------------------------------------------------- /src/FsToolkit.ErrorHandling/TaskValueOptionOp.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.Operator.TaskValueOption 2 | 3 | open FsToolkit.ErrorHandling 4 | 5 | [] 6 | module TaskValueOption = 7 | 8 | let inline () ([] f) x = TaskValueOption.map f x 9 | let inline (<*>) f x = TaskValueOption.apply f x 10 | let inline (>>=) x ([] f) = TaskValueOption.bind f x 11 | -------------------------------------------------------------------------------- /tests/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | true 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.AsyncSeq.Tests" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/FsToolkit.ErrorHandling.AsyncSeq.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0;net9.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.AsyncSeq.Tests/Main.fs: -------------------------------------------------------------------------------- 1 | module FsToolkit.ErrorHandling.AsyncSeq.Tests 2 | 3 | #if FABLE_COMPILER_PYTHON || FABLE_COMPILER_JAVASCRIPT 4 | open Fable.Pyxpecto 5 | #endif 6 | #if !FABLE_COMPILER 7 | open Expecto 8 | 9 | [] //needed for `dotnet test` to work 10 | #endif 11 | let allTests = testList "All Tests" [ AsyncSeq.allTests ] 12 | 13 | // This is possibly the most magic used to make this work. 14 | // Js and ts cannot use `Async.RunSynchronously`, instead they use `Async.StartAsPromise`. 15 | // Here we need the transpiler not to worry about the output type. 16 | #if !FABLE_COMPILER_JAVASCRIPT && !FABLE_COMPILER_TYPESCRIPT 17 | let (!!) (any: 'a) = any 18 | #endif 19 | #if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT 20 | open Fable.Core.JsInterop 21 | #endif 22 | 23 | [] 24 | let main argv = 25 | #if FABLE_COMPILER_JAVASCRIPT || FABLE_COMPILER_TYPESCRIPT || FABLE_COMPILER_PYTHON 26 | !!Pyxpecto.runTests [||] allTests 27 | #endif 28 | #if !FABLE_COMPILER 29 | Tests.runTestsWithCLIArgs [] Array.empty allTests 30 | #endif 31 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.IcedTasks.Tests/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.IcedTasks.Tests" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.IcedTasks.Tests/FsToolkit.ErrorHandling.IcedTasks.Tests.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | $(NoWarn); FS3511 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.IcedTasks.Tests/Main.fs: -------------------------------------------------------------------------------- 1 | namespace FsToolkit.ErrorHandling.IcedTasks.Tests 2 | 3 | open Expecto 4 | 5 | module Main = 6 | [] 7 | let main argv = 8 | Tests.runTestsInAssemblyWithCLIArgs [] argv 9 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.JobResult.Tests/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.JobResult.Tests" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.JobResult.Tests/Expect.JobOption.fs: -------------------------------------------------------------------------------- 1 | namespace Expects.JobOption 2 | 3 | module Expect = 4 | open Expecto 5 | open Hopac 6 | 7 | let hasJobValue v jobX = 8 | let x = run jobX 9 | 10 | if v = x then 11 | () 12 | else 13 | Tests.failtestf "Expected %A, was %A." v x 14 | 15 | 16 | let hasJobSomeValue v jobX = 17 | let x = run jobX 18 | TestHelpers.Expect.hasSomeValue v x 19 | 20 | 21 | let hasJobNoneValue jobX = 22 | let x = run jobX 23 | TestHelpers.Expect.hasNoneValue x 24 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.JobResult.Tests/Expect.JobResult.fs: -------------------------------------------------------------------------------- 1 | namespace Expects.JobResult 2 | 3 | module Expect = 4 | open Expecto 5 | open Hopac 6 | 7 | let hasJobValue v jobX = 8 | let x = run jobX 9 | 10 | if v = x then 11 | () 12 | else 13 | Tests.failtestf "Expected %A, was %A." v x 14 | 15 | let hasJobOkValue v (jobX: Job<_>) = 16 | job { 17 | let! x = jobX 18 | TestHelpers.Expect.hasOkValue v x 19 | } 20 | 21 | let hasJobOkValueSync v jobX = 22 | let x = run jobX 23 | TestHelpers.Expect.hasOkValue v x 24 | 25 | let hasJobErrorValue v (jobX: Job<_>) = 26 | job { 27 | let! x = jobX 28 | TestHelpers.Expect.hasErrorValue v x 29 | } 30 | 31 | let hasJobErrorValueSync v jobX = 32 | let x = run jobX 33 | TestHelpers.Expect.hasErrorValue v x 34 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.JobResult.Tests/Main.fs: -------------------------------------------------------------------------------- 1 | module FsToolkit.ErrorHandling.TaskResult.Tests 2 | 3 | open Expecto 4 | 5 | [] 6 | let main argv = 7 | Tests.runTestsInAssemblyWithCLIArgs [] argv 8 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.JobResult.Tests/Result.fs: -------------------------------------------------------------------------------- 1 | module Result 2 | 3 | open Hopac 4 | open Expecto 5 | open FsToolkit.ErrorHandling 6 | 7 | 8 | [] 9 | let sequenceJobTests = 10 | testList "sequenceJob Tests" [ 11 | testCase "sequenceJob returns the job value if Ok" 12 | <| fun _ -> 13 | let resJob = 14 | job { return "foo" } 15 | |> Ok 16 | 17 | let value = 18 | resJob 19 | |> Result.sequenceJob 20 | |> run 21 | 22 | Expect.equal value (Ok "foo") "" 23 | 24 | testCase "sequenceJob returns the error value if Error" 25 | <| fun _ -> 26 | let resJob = Error "foo" 27 | 28 | let value = 29 | resJob 30 | |> Result.sequenceJob 31 | |> run 32 | 33 | Expect.equal value (Error "foo") "" 34 | ] 35 | -------------------------------------------------------------------------------- /tests/FsToolkit.ErrorHandling.Tests/AssemblyInfo.fs: -------------------------------------------------------------------------------- 1 | // Auto-Generated by FAKE; do not edit 2 | namespace System 3 | open System.Reflection 4 | 5 | [] 6 | [] 7 | [] 8 | [] 9 | [] 10 | [] 11 | do () 12 | 13 | module internal AssemblyVersionInformation = 14 | let [] AssemblyTitle = "FsToolkit.ErrorHandling.Tests" 15 | let [] AssemblyProduct = "FsToolkit.ErrorHandling" 16 | let [] AssemblyDescription = "FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling." 17 | let [] AssemblyVersion = "5.0.0" 18 | let [] AssemblyFileVersion = "5.0.0" 19 | let [] AssemblyConfiguration = "Release" 20 | -------------------------------------------------------------------------------- /tools/FunctionMap/FunctionMap.fsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | false 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | --------------------------------------------------------------------------------