From 8dab5d01ec21139cd31f63f355dcccd101b9562f Mon Sep 17 00:00:00 2001 From: Bronson Bata Date: Fri, 7 Jul 2023 23:35:49 -0500 Subject: [PATCH] Added BindMappings documentation to gitbook --- gitbook/BindMappings.md | 59 ++++++++++++++++++++++++++--------------- gitbook/SUMMARY.md | 26 +++++++++--------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/gitbook/BindMappings.md b/gitbook/BindMappings.md index f3d8cd83..637dafc4 100644 --- a/gitbook/BindMappings.md +++ b/gitbook/BindMappings.md @@ -2,7 +2,7 @@ This pages shows you which computation expressions can implicitly bind to other CEs -Example +## Example Here we can bind an 'T Option to 'T AsyncOption without having to lift from one type to another. See [here](https://fsharpforfunandprofit.com/posts/elevated-world/) for a better understanding on 'lifting'. To associate with the table below, the AsyncOption is the CE and the Option is the CE that can bind to it. @@ -13,24 +13,39 @@ asyncOption { } ``` -*Each CE can bind to itself so we don't list that here to reduce redundancy* - -| CE | Can Bind (FsToolkit.ErrorHandling) | Can Bind (FsToolkit.ErrorHandling.IcedTasks) | Can Bind (FsToolkit.ErrorHandling.JobResult) | Can Bind (FsToolkit.ErrorHandling.TaskResult) | -|:--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------|--|-----------------------------------------------| -| AsyncOption | Async, Task, Option | || | -| AsyncResult | Result, Choice, Async, Task | || TaskResult | -| AsyncResultOption | AsyncResult, AsyncOption, Result, Choice, Async, Task, Option | || TaskResultOption, TaskResult, TaskOption | -| AsyncValidation | AsyncResult, Validation, Result, Choice, Async | || | -| CancellableTaskResult | AsyncResult, AsyncChoice, Result, Choice, Async, Task, | CancellableTask1, ColdTask4 || ValueTaskResult, TaskResult | -| CancellableTaskValidation | AsyncResult, AsyncChoice, ValueTaskResult3, TaskResult3, Validation, Result, Choice, Async, Task, CancellableTask1, ColdTask4 | || | -| JopOption | Job 2, TaskOption 3, AsyncOption | || | -| JobResult | | || | -| JobResultOption | | || | -| Option | | || | -| Result | | || | -| ResultOption | | || | -| Task | | || | -| TaskOption | | || | -| TaskResult | | || | -| TaskResultOption | | || | -| Validation | | || | +### Note + +Each CE can bind to itself so we don't list that here to reduce clutter + +| CE | Can Bind | +| :------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------- | +| AsyncOption | Async, Task, Option | +| AsyncResult | Result, Choice, Async, Task, TaskResult | +| AsyncResultOption | TaskResultOption, AsyncResult, TaskResult, AsyncOption, Result, Choice, Async, Task, Option, | +| AsyncValidation | AsyncResult, Validation, Result, Choice, Async | +| CancellableTaskResult | ValueTaskResult, AsyncResult, TaskResult, AsyncChoice, CancellableTask, ColdTask, Result, Choice, Async, Task | +| CancellableTaskValidation | AsyncValidation, ValueTaskResult, AsyncResult, TaskResult, AsyncChoice, CancellableTask, ColdTask, Validation, Result, Choice, Async, Task | +| JopOption | TaskOption, AsyncOption, Job, Async, Task, Option | +| JobResult | AsyncResult, TaskResult, Job, Result, Choice, Async, Task | +| JobResultOption | | +| Option | ValueOption, nullable object | +| Result | Choice | +| ResultOption | | +| Task | | +| TaskOption | ValueTaskOption, AsyncOption, PlyOption, Async, Task, ValueTask, Option | +| TaskResult | AsyncResult, PlyResult, TaskResult, ValueTaskResult, Result, Choice, Ply, Async, Task, ValueTask | +| TaskResultOption | | +| Validation | Result, Choice | + +## Don't see the bindings you want? + +Luckily the CEs are extensible so you can add your own Source overloads to the builders. Take for example the AsyncOption builder. Let's pretend it didn't support being able to bind Async values. You can add an overload as follows shown below. The code shown would go in your own codebase, unless you'd want to submit a PR 😉 If you need an example of how to do this with various syntax, check out any of the CE files in the codebase. + +```fsharp +module MyCustomCodeModule = + + type AsyncOptionBuilder with + member _.Source(value: Async<'T>) : Async<'T option> = + value |> Async.map Some + +``` diff --git a/gitbook/SUMMARY.md b/gitbook/SUMMARY.md index bba52158..104e3b89 100644 --- a/gitbook/SUMMARY.md +++ b/gitbook/SUMMARY.md @@ -102,18 +102,18 @@ * [Operators](cancellableTaskValidation/operators.md) * FsToolkit.ErrorHandling.JobResult * JobResult - * [map](jobResult/map.md) - * [map2](jobResult/map2.md) - * [map3](jobResult/map3.md) - * [mapError](jobResult/mapError.md) - * [apply](jobResult/apply.md) - * [foldResult](jobResult/foldResult.md) - * [ofTask](jobResult/ofTask.md) - * [bind](jobResult/bind.md) - * [ignore](jobResult/ignore.md) - * [Computation Expression](jobResult/ce.md) - * [Operators](jobResult/operators.md) - * [Other Functions](jobResult/others.md) + * [map](jobResult/map.md) + * [map2](jobResult/map2.md) + * [map3](jobResult/map3.md) + * [mapError](jobResult/mapError.md) + * [apply](jobResult/apply.md) + * [foldResult](jobResult/foldResult.md) + * [ofTask](jobResult/ofTask.md) + * [bind](jobResult/bind.md) + * [ignore](jobResult/ignore.md) + * [Computation Expression](jobResult/ce.md) + * [Operators](jobResult/operators.md) + * [Other Functions](jobResult/others.md) * FsToolkit.ErrorHandling.TaskResult * TaskResult * [map](taskResult/map.md) @@ -144,3 +144,5 @@ * [Operators](taskResultOption/operators.md) * TaskOption * [Computation Expression](taskOption/ce.md) +* General Docs + * [Bind Mappings](bindMappings.md)