Skip to content

Commit dca95e2

Browse files
committed
improve docs
1 parent e8abba4 commit dca95e2

1 file changed

Lines changed: 3 additions & 25 deletions

File tree

docs/AsyncSeqTransforming.fsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ open FSharp.Control
3636

3737
(**
3838
39-
## Transforming Sequences
40-
41-
### Using computation expressions
39+
## Transforming Sequences with computation expressions
4240
4341
The most general and simplest way to transform asynchronous sequences is to write a function that accepts an `AsyncSeq<_>` and returns an `AsyncSeq<_>` and is implemented using an `asyncSeq { ... }` computation expression. For example, the following function transforms a sequence of integers into a sequence of strings that labels each integer as even or odd:
4442
@@ -74,7 +72,7 @@ let transformWithAsync (input: AsyncSeq<int>) : AsyncSeq<string> =
7472

7573
(**
7674
77-
### map and mapAsync
75+
## Using map and mapAsync
7876
7977
Instead of writing a full computation expression, you can use `AsyncSeq.map` to transform each element of a sequence synchronously:
8078
@@ -99,7 +97,7 @@ let lengths : AsyncSeq<int> =
9997

10098
(**
10199
102-
### filter and filterAsync
100+
## Using filter and filterAsync
103101
104102
`AsyncSeq.filter` keeps only elements satisfying a synchronous predicate:
105103
@@ -121,23 +119,3 @@ let isInteresting (s: string) : Async<bool> =
121119
let interesting : AsyncSeq<string> =
122120
strings |> AsyncSeq.filterAsync isInteresting
123121

124-
(**
125-
126-
### mapFoldAsync
127-
128-
`AsyncSeq.mapFoldAsync` combines a map and a fold in a single pass. The folder function receives
129-
the current accumulator state and an element, and returns an `Async` of a *(result, newState)* pair.
130-
The call returns the array of mapped results together with the final state:
131-
132-
*)
133-
134-
let words = asyncSeq { yield! [ "F#"; "is"; "great" ] }
135-
136-
// Number each element with a running index, and count total characters as state.
137-
let numberAndCount : Async<string array * int> =
138-
words
139-
|> AsyncSeq.mapFoldAsync
140-
(fun totalChars word -> async {
141-
let numbered = sprintf "%d: %s" totalChars word
142-
return numbered, totalChars + word.Length })
143-
0

0 commit comments

Comments
 (0)