Skip to content

Commit def0948

Browse files
authored
Add missing documentation for modules in FsToolkit.ErrorHandling namespace (#312)
* Finish adding documentation for modules thru Task * Filled in the rest of the missing gitbook pages for the namespace
1 parent d7e69da commit def0948

File tree

35 files changed

+1135
-46
lines changed

35 files changed

+1135
-46
lines changed

gitbook/SUMMARY.md

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
* [map](resultOption/map.md)
7474
* [map2](resultOption/map2.md)
7575
* [map3](resultOption/map3.md)
76-
* [mapError](pr.md)
76+
* [mapError](resultOption/mapError.md)
7777
* [Operators](resultOption/operators.md)
7878
* [zip](resultOption/zip.md)
7979
* [zipError](resultOption/zipError.md)
@@ -96,8 +96,8 @@
9696
* [mapError](asyncResult/mapError.md)
9797
* [Operators](asyncResult/operators.md)
9898
* [Other Functions](asyncResult/others.md)
99-
* [zip](pr.md)
100-
* [zipError](pr.md)
99+
* [zip](asyncResult/zip.md)
100+
* [zipError](asyncResult/zipError.md)
101101
* List
102102
* [traverseAsyncResultM](list/traverseAsyncResultM.md)
103103
* [sequenceAsyncResultM](list/sequenceAsyncResultM.md)
@@ -139,35 +139,34 @@
139139
* [ofResult](asyncResultOption/ofResult.md)
140140

141141
* Task
142-
* [apply](pr.md)
143-
* [bind](pr.md)
144-
* [bindV](pr.md)
145-
* [catch](pr.md)
146-
* [Computation Expression](pr.md)
147-
* [ignore](pr.md)
148-
* [map](pr.md)
149-
* [mapV](pr.md)
150-
* [map2](pr.md)
151-
* [map3](pr.md)
152-
* [ofUnit](pr.md)
153-
* [zip](pr.md)
142+
* [apply](task/apply.md)
143+
* [bind](task/bind.md)
144+
* [bindV](task/bindV.md)
145+
* [catch](task/catch.md)
146+
* [Computation Expression](task/ce.md)
147+
* [ignore](task/ignore.md)
148+
* [map](task/map.md)
149+
* [mapV](task/mapV.md)
150+
* [map2](task/map2.md)
151+
* [map3](task/map3.md)
152+
* [zip](task/zip.md)
154153
* Transforms
155154
* [ofUnit](task/ofUnit.md)
156155

157156
* TaskOption
158-
* [apply](pr.md)
159-
* [bind](pr.md)
157+
* [apply](taskOption/apply.md)
158+
* [bind](taskOption/bind.md)
160159
* [Computation Expression](taskOption/ce.md)
161-
* [either](pr.md)
162-
* [map](pr.md)
163-
* [some](pr.md)
164-
* [zip](pr.md)
160+
* [either](taskOption/either.md)
161+
* [map](taskOption/map.md)
162+
* [Other Functions](taskOption/others.md)
163+
* [zip](taskOption/zip.md)
165164

166165
* TaskResult
167166
* [apply](taskResult/apply.md)
168167
* [bind](taskResult/bind.md)
169168
* [check](taskResult/check.md)
170-
* [catch](pr.md)
169+
* [catch](taskResult/catch.md)
171170
* [Computation Expression](taskResult/ce.md)
172171
* [ignore](taskResult/ignore.md)
173172
* [map](taskResult/map.md)
@@ -177,8 +176,8 @@
177176
* [Operators](taskResult/operators.md)
178177
* [Other Functions](taskResult/others.md)
179178
* [error](taskResult/error.md)
180-
* [zip](pr.md)
181-
* [zipError](pr.md)
179+
* [zip](taskResult/zip.md)
180+
* [zipError](taskResult/zipError.md)
182181
* Lists
183182
* [traverseTaskResultM](list/traverseTaskResultM.md)
184183
* [sequenceTaskResultM](list/sequenceTaskResultM.md)
@@ -203,13 +202,13 @@
203202
* [apply](validation/apply.md)
204203
* [Computation Expression](validation/ce.md)
205204
* [error](validation/error.md)
206-
* [map](pr.md)
205+
* [map](validation/map.md)
207206
* [map2](validation/map2.md)
208207
* [map3](validation/map3.md)
209-
* [mapError](pr.md)
210-
* [mapErrors](pr.md)
208+
* [mapError](validation/mapError.md)
209+
* [mapErrors](validation/mapErrors.md)
211210
* [Operators](validation/operators.md)
212-
* [zip](pr.md)
211+
* [zip](validation/zip.md)
213212
* Transforms
214213
* [ofChoice](validation/ofChoice.md)
215214
* [ofResult](validation/ofResult.md)
@@ -218,13 +217,13 @@
218217
* [apply](asyncValidation/apply.md)
219218
* [Computation Expression](asyncValidation/ce.md)
220219
* [error](asyncValidation/error.md)
221-
* [map](pr.md)
220+
* [map](asyncValidation/map.md)
222221
* [map2](asyncValidation/map2.md)
223222
* [map3](asyncValidation/map3.md)
224-
* [mapError](pr.md)
225-
* [mapErrors](pr.md)
223+
* [mapError](asyncValidation/mapError.md)
224+
* [mapErrors](asyncValidation/mapErrors.md)
226225
* [Operators](asyncValidation/operators.md)
227-
* [zip](pr.md)
226+
* [zip](asyncValidation/zip.md)
228227
* Transforms
229228
* [ofChoice](asyncValidation/ofChoice.md)
230229
* [ofResult](asyncValidation/ofResult.md)

gitbook/asyncResult/zip.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# AsyncResult.zip
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
## Function Signature
6+
7+
```fsharp
8+
Async<Result<'leftOk, 'error>> -> Async<Result<'rightOk, 'error>> -> Async<Result<'leftOk * 'rightOk, 'error>>
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+
```

gitbook/asyncResult/zipError.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# AsyncResult.zipError
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
## Function Signature
6+
7+
```fsharp
8+
Async<Result<'ok, 'leftError>> -> Async<Result<'ok, 'rightError>> -> Async<Result<'ok, 'leftError * 'rightError>>
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+
```

gitbook/asyncValidation/map.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# AsyncValidation.map
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
`map` applies a transformation to the value inside an `AsyncValidation` 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 `AsyncValidation`. If the original `AsyncValidation` is an `Error`, `map` does nothing and returns the same `Error` unchanged.
6+
7+
## Function Signature
8+
9+
```fsharp
10+
('okInput -> 'okOutput) -> AsyncValidation<'okInput, 'error> -> AsyncValidation<'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+
AsyncValidation.ok "foo" // AsyncValidation<string, string>
28+
|> AsyncValidation.map remainingCharacters // AsyncValidation<int, string>
29+
30+
// async { Ok 277 }
31+
```
32+
33+
### Example 2
34+
35+
```fsharp
36+
let result =
37+
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
38+
|> AsyncValidation.map remainingCharacters // AsyncValidation<int, string>
39+
40+
// async { Error ["bad things happened"] }
41+
```

gitbook/asyncValidation/mapError.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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<string, string>
31+
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>
32+
33+
// async { Ok "all good" }
34+
```
35+
36+
### Example 2
37+
38+
```fsharp
39+
let result =
40+
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
41+
|> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>
42+
43+
// async { Error [1] }
44+
```

gitbook/asyncValidation/mapErrors.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AsyncValidation.mapErrors
2+
3+
Namespace: `FsToolkit.ErrorHandling`
4+
5+
Similar to [AsyncValidation.mapError](../asyncValidation/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) -> 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 (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+
AsyncValidation.ok "all good" // AsyncValidation<string, string>
31+
|> AsyncValidation.mapErrors getErrorCode // AsyncValidation<string, int>
32+
33+
// async { Ok "all good" }
34+
```
35+
36+
### Example 2
37+
38+
```fsharp
39+
let result : AsyncValidation<string, int> =
40+
AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
41+
|> AsyncValidation.mapErrors getErrorCode // AsyncValidation<string, int>
42+
43+
// async { Error [1] }
44+
```

gitbook/asyncValidation/zip.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
```

gitbook/result/map.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Namespace: `FsToolkit.ErrorHandling`
77
## Function Signature
88

99
```fsharp
10-
('okInput -> 'okOutput) -> Result<'okInput, 'error>
11-
-> Result<'okOutput, 'error>
10+
('okInput -> 'okOutput) -> Result<'okInput, 'error> -> Result<'okOutput, 'error>
1211
```
1312

1413
## Examples
@@ -26,7 +25,7 @@ let remainingCharacters (prompt: string) =
2625
```fsharp
2726
let result =
2827
Ok "foo" // Result<string, string>
29-
|> ResultOption.map remainingCharacters // Result<int, string>
28+
|> Result.map remainingCharacters // Result<int, string>
3029
3130
// Ok 277
3231
```
@@ -36,7 +35,7 @@ let result =
3635
```fsharp
3736
let result =
3837
Error "bad things happened" // Result<string, string>
39-
|> ResultOption.map remainingCharacters // Result<int, string>
38+
|> Result.map remainingCharacters // Result<int, string>
4039
4140
// Error "bad things happened"
4241
```

0 commit comments

Comments
 (0)