Skip to content

Commit d0d5660

Browse files
committed
Filled in the rest of the missing gitbook pages for the namespace
1 parent 3874432 commit d0d5660

File tree

22 files changed

+700
-30
lines changed

22 files changed

+700
-30
lines changed

gitbook/SUMMARY.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,19 @@
154154
* [ofUnit](task/ofUnit.md)
155155

156156
* TaskOption
157-
* [apply](pr.md)
158-
* [bind](pr.md)
157+
* [apply](taskOption/apply.md)
158+
* [bind](taskOption/bind.md)
159159
* [Computation Expression](taskOption/ce.md)
160-
* [either](pr.md)
161-
* [map](pr.md)
162-
* [some](pr.md)
163-
* [zip](pr.md)
160+
* [either](taskOption/either.md)
161+
* [map](taskOption/map.md)
162+
* [Other Functions](taskOption/others.md)
163+
* [zip](taskOption/zip.md)
164164

165165
* TaskResult
166166
* [apply](taskResult/apply.md)
167167
* [bind](taskResult/bind.md)
168168
* [check](taskResult/check.md)
169-
* [catch](pr.md)
169+
* [catch](taskResult/catch.md)
170170
* [Computation Expression](taskResult/ce.md)
171171
* [ignore](taskResult/ignore.md)
172172
* [map](taskResult/map.md)
@@ -176,8 +176,8 @@
176176
* [Operators](taskResult/operators.md)
177177
* [Other Functions](taskResult/others.md)
178178
* [error](taskResult/error.md)
179-
* [zip](pr.md)
180-
* [zipError](pr.md)
179+
* [zip](taskResult/zip.md)
180+
* [zipError](taskResult/zipError.md)
181181
* Lists
182182
* [traverseTaskResultM](list/traverseTaskResultM.md)
183183
* [sequenceTaskResultM](list/sequenceTaskResultM.md)
@@ -202,13 +202,13 @@
202202
* [apply](validation/apply.md)
203203
* [Computation Expression](validation/ce.md)
204204
* [error](validation/error.md)
205-
* [map](pr.md)
205+
* [map](validation/map.md)
206206
* [map2](validation/map2.md)
207207
* [map3](validation/map3.md)
208-
* [mapError](pr.md)
209-
* [mapErrors](pr.md)
208+
* [mapError](validation/mapError.md)
209+
* [mapErrors](validation/mapErrors.md)
210210
* [Operators](validation/operators.md)
211-
* [zip](pr.md)
211+
* [zip](validation/zip.md)
212212
* Transforms
213213
* [ofChoice](validation/ofChoice.md)
214214
* [ofResult](validation/ofResult.md)
@@ -217,13 +217,13 @@
217217
* [apply](asyncValidation/apply.md)
218218
* [Computation Expression](asyncValidation/ce.md)
219219
* [error](asyncValidation/error.md)
220-
* [map](pr.md)
220+
* [map](asyncValidation/map.md)
221221
* [map2](asyncValidation/map2.md)
222222
* [map3](asyncValidation/map3.md)
223-
* [mapError](pr.md)
224-
* [mapErrors](pr.md)
223+
* [mapError](asyncValidation/mapError.md)
224+
* [mapErrors](asyncValidation/mapErrors.md)
225225
* [Operators](asyncValidation/operators.md)
226-
* [zip](pr.md)
226+
* [zip](asyncValidation/zip.md)
227227
* Transforms
228228
* [ofChoice](asyncValidation/ofChoice.md)
229229
* [ofResult](asyncValidation/ofResult.md)

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+
```
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+
```
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
```

gitbook/result/mapError.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Result.mapError
1+
# Result.mapError
22

33
Namespace: `FsToolkit.ErrorHandling`
44

@@ -27,18 +27,18 @@ let getErrorCode (message: string) =
2727

2828
```fsharp
2929
let result =
30-
Ok "bad things happened" // Result<string, string>
31-
|> ResultOption.mapError getErrorCode // Result<string, int>
30+
Ok "all good" // Result<string, string>
31+
|> Result.mapError getErrorCode // Result<string, int>
3232
33-
// Ok "bad things happened"
33+
// Ok "all good"
3434
```
3535

3636
### Example 2
3737

3838
```fsharp
3939
let result =
4040
Error "bad things happened" // Result<string, string>
41-
|> ResultOption.mapError getErrorCode // Result<string, int>
41+
|> Result.mapError getErrorCode // Result<string, int>
4242
4343
// Error 1
4444
```

gitbook/task/catch.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ let result = Task.catch (Task.singleton 42)
3131

3232
### Example 2
3333

34-
Given the function
35-
3634
```fsharp
3735
let result = Task.catch (taskThrow ())
3836
// task { Choice2Of2(exn("something bad happened")) }

gitbook/taskOption/apply.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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<string option>
25+
|> TaskOption.apply (TaskOption.some characterCount) // Task<int option>
26+
27+
// task { Some 3 }
28+
```
29+
30+
### Example 2
31+
32+
```fsharp
33+
let result =
34+
Task.singleton None // Task<string option>
35+
|> TaskOption.apply (TaskOption.some characterCount) // Task<int option>
36+
37+
// task { None }
38+
```
39+
40+
### Example 3
41+
42+
```fsharp
43+
let result : Task<int option> =
44+
TaskOption.some "foo" // Task<string option>
45+
|> TaskOption.apply (Task.singleton None) // Task<int option>
46+
47+
// task { None }
48+
```

0 commit comments

Comments
 (0)