Skip to content

Commit d91aaa4

Browse files
docs: Add IAsyncEnumerable gitbook documentation for task CEs (#350)
* Initial plan * Add IAsyncEnumerable documentation to task CE gitbook docs Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
1 parent 45e1abd commit d91aaa4

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

gitbook/taskOption/ce.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ let addResult = taskOption {
2424
do! updatePerson person
2525
}
2626
```
27+
28+
### Example 2 - IAsyncEnumerable
29+
30+
The `taskOption` CE supports `for .. in ..` iteration over `IAsyncEnumerable<'T>` sequences. Iteration stops immediately when the body returns `None`, without consuming further elements.
31+
32+
```fsharp
33+
tryProcessItem : Item -> Task<unit option>
34+
getItemsAsync : unit -> IAsyncEnumerable<Item>
35+
```
36+
37+
```fsharp
38+
// Task<string option>
39+
let processItems () =
40+
taskOption {
41+
for item in getItemsAsync () do
42+
do! tryProcessItem item
43+
return "done"
44+
}
45+
// Returns None and stops iteration on the first None result
46+
```
47+
48+
The `backgroundTaskOption` CE inherits this support automatically.

gitbook/taskResult/ce.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ let login (username: string) (password: string) : Task<Result<AuthToken, LoginEr
3333
return! user |> createAuthToken |> Result.mapError TokenErr
3434
}
3535
```
36+
37+
### Example 2 - IAsyncEnumerable
38+
39+
The `taskResult` CE supports `for .. in ..` iteration over `IAsyncEnumerable<'T>` sequences. Iteration stops immediately when the body returns an `Error`, without consuming further elements.
40+
41+
```fsharp
42+
validate : Item -> Task<Result<ValidItem, string>>
43+
save : ValidItem -> Task<Result<unit, string>>
44+
getItemsAsync : unit -> IAsyncEnumerable<Item>
45+
```
46+
47+
```fsharp
48+
// Task<Result<string, string>>
49+
let processItems () =
50+
taskResult {
51+
for item in getItemsAsync () do
52+
let! validated = validate item
53+
do! save validated
54+
return "done"
55+
}
56+
// Stops iteration immediately on the first Error
57+
```
58+
59+
The `backgroundTaskResult` CE inherits this support automatically.

gitbook/taskValidation/ce.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,27 @@ let addResult = taskValidation {
3939
4040
// task { return Error [ "Am"; "I"; "async?" ] }
4141
```
42+
43+
### IAsyncEnumerable
44+
45+
The `taskValidation` CE supports `for .. in ..` iteration over `IAsyncEnumerable<'T>` sequences. Iteration stops immediately when the body returns an `Error`, without consuming further elements.
46+
47+
```fsharp
48+
validate : Item -> Task<Result<ValidItem, string>>
49+
save : ValidItem -> Task<Result<unit, string>>
50+
getItemsAsync : unit -> IAsyncEnumerable<Item>
51+
```
52+
53+
```fsharp
54+
// Task<Result<string, string list>>
55+
let processItems () =
56+
taskValidation {
57+
for item in getItemsAsync () do
58+
let! validated = validate item
59+
do! save validated
60+
return "done"
61+
}
62+
// Stops iteration immediately on the first Error
63+
```
64+
65+
The `backgroundTaskValidation` CE inherits this support automatically.

gitbook/taskValueOption/ce.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ let addResult = taskValueOption {
2424
do! updatePerson person
2525
}
2626
```
27+
28+
### Example 2 - IAsyncEnumerable
29+
30+
The `taskValueOption` CE supports `for .. in ..` iteration over `IAsyncEnumerable<'T>` sequences. Iteration stops immediately when the body returns `ValueNone`, without consuming further elements.
31+
32+
```fsharp
33+
tryProcessItem : Item -> Task<unit voption>
34+
getItemsAsync : unit -> IAsyncEnumerable<Item>
35+
```
36+
37+
```fsharp
38+
// Task<string voption>
39+
let processItems () =
40+
taskValueOption {
41+
for item in getItemsAsync () do
42+
do! tryProcessItem item
43+
return "done"
44+
}
45+
// Returns ValueNone and stops iteration on the first ValueNone result
46+
```
47+
48+
The `backgroundTaskValueOption` CE inherits this support automatically.

0 commit comments

Comments
 (0)