Skip to content

Commit

Permalink
Added BindMappings documentation to gitbook
Browse files Browse the repository at this point in the history
  • Loading branch information
1eyewonder authored and TheAngryByrd committed Jul 9, 2023
1 parent 7266305 commit 8dab5d0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
59 changes: 37 additions & 22 deletions gitbook/BindMappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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, | CancellableTask<sup>1</sup>, ColdTask<sup>4</sup> || ValueTaskResult, TaskResult |
| CancellableTaskValidation | AsyncResult, AsyncChoice, ValueTaskResult<sup>3</sup>, TaskResult<sup>3</sup>, Validation, Result, Choice, Async, Task, CancellableTask<sup>1</sup>, ColdTask<sup>4</sup> | || |
| JopOption | Job <sup>2</sup>, TaskOption <sup>3</sup>, 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
```
26 changes: 14 additions & 12 deletions gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -144,3 +144,5 @@
* [Operators](taskResultOption/operators.md)
* TaskOption
* [Computation Expression](taskOption/ce.md)
* General Docs
* [Bind Mappings](bindMappings.md)

0 comments on commit 8dab5d0

Please sign in to comment.