You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// This block of code is omitted in the generated HTML documentation. Use
3
3
// it to define helpers that you do not want to show in the documentation.
4
-
(**
5
-
TO-DO Add some docs here !
6
-
=========================
4
+
5
+
// For some reason AsyncDownloadString is not found during doc build. The following is a dumb implementation just to make the compiler happy.
6
+
// TODO find out why.
7
+
typeSystem.Net.WebClientwithmemberwc.AsyncDownloadString(uri:System.Uri)=async{return wc.DownloadString uri }
8
+
9
+
(*
10
+
SeqT<Monad<bool>, 'T>
11
+
=====================
12
+
13
+
This is the the Monad Transformer for `seq<'T>` so it adds sequencing to existing monads by composing then with `seq<'T>`.
14
+
15
+
Any monad can be composed, but a very typical usage is when combined with `Async` or `Task`, which gives rise to what's called async sequences.
16
+
17
+
Therefore the [AsyncSeq](https://github.com/fsprojects/FSharp.Control.AsyncSeq) library can be considered a specialization of this monad in Async.
18
+
19
+
The original post from AsyncSeq can be found [here](http://tomasp.net/blog/async-sequences.aspx) and we can run those examples with `SeqT` by adapting the code.
20
+
21
+
In order to do so we need to be aware of the design differences of both implementations.
22
+
23
+
| AsyncSeq | SeqT | Notes |
24
+
|--|--|:--:|
25
+
|`AsyncSeq<'T>` |`SeqT<Async<bool>, 'T>` | |
26
+
|`asyncSeq { .. }` |`monad.plus { .. }` | At some point it needs to be inferred as `SeqT<Async<bool>, 'T>`, or it can be specified with type parameters: `monad<SeqT<Async<bool>, 'T>>.plus` |
27
+
|`let! x = y` |`let! x = SeqT.lift y` | No auto lifting. Lifting should be explicit. |
28
+
|`do! x` |`do! x` | '' |
29
+
|`for x in s` |`let! x = s` | When `s: AsyncSeq<'T>` otherwise `for` is still ok with regular sequences. |
30
+
|`AsyncSeq.[function]` |`SeqT.[function]` | See differences in functions below. |
|`AsyncSeq.skip` |`SeqT.drop` | `.skip` is available but consistently with F# collections, it throws when the sequence doesn't have enough elements. |
33
+
|`AsyncSeq.take` |`SeqT.truncate` | `.take` is available but consistently with F# collections, it throws when the sequence doesn't have enough elements. |
34
+
|`AsyncSeq.toBlockingSequence` |`SeqT.run >> Async.RunSynchronously` | Not really the same but semantically equivalent. |
35
+
|`AsyncSeq.toListAsync` |`SeqT.runAsList` | |
36
+
|`AsyncSeq.toArrayAsync` |`SeqT.runAsArray` | |
37
+
|`AsyncSeq.zipWith` |`SeqT.map2` | Aligned with F# collections. |
38
+
|`AsyncSeq.zipWithAsync` |`SeqT.map2M` | '' |
39
+
|`AsyncSeq.ofObservable` |`Observable.toAsyncSeq` |`.toAsyncTask` is also available. |
40
+
|`AsyncSeq.toObservable` |`Observable.ofAsyncSeq` |`.ofAsyncTask` is also available. |
To make it work with tasks simply add `|> Async.StartAsTask` between `wc.AsyncDownloadString (Uri url)` and `|> SeqT.lift` then run eveything but the `printPages |> Async.Start`.
0 commit comments