Skip to content

Commit edfc8c8

Browse files
authored
Merge pull request #3 from Thorium/add-some-docs
Documentation update
2 parents e5ace1a + 35b570d commit edfc8c8

File tree

5 files changed

+79
-11
lines changed

5 files changed

+79
-11
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# FSharp.Control.R3
22

3-
Extensions and wrappers for using R3 with F#.
3+
Extensions and wrappers for using [R3](https://github.com/Cysharp/R3) with F#.
4+
5+
6+
[Documentation](https://fsprojects.github.io/FSharp.Control.R3/)
7+
48

59
---
610

docsSrc/Explanations/Background.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@ index: 1
77

88
# Background
99

10-
Here's a core concept and reasons why this exists at a deeper level.
10+
`IObservable<T>` is .NET way of dealing with lazy event streams with publish/subscribe-pattern called Reactive Programming, "LINQ to Events and async operations".
11+
12+
Where a standard list (IEnumerable) is pull-based, IObservable is a push-based (infinite) list, like "a lazy list of mouse events": when an event happens, the corresponding list gets a new value.
13+
If Nullable is just "a list of 0 or 1", then async-await could be just an IObservable of 0 or 1.
14+
15+
There are many advantages of using reactive programming and Rx:
16+
  - Manual thread/lock -handling can be avoided
17+
  - No temporary class variables to capture the current or some previous state
18+
  - Testing is easy: generate lists like they would be event-lists.
19+
  - Testing the wrong async event order is easy.
20+
  - Also, testing long-duration workflows is easy as you can "fake" time passing
21+
22+
It's always good to have alternatives, and if R3 is your alternative to Rx, then `FSharp.Control.R3` is your F# wrapper, like `FSharp.Control.Reactive` F#.

docsSrc/How_Tos/Doing_A_Thing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ index: 1
77

88
# How To do a first thing
99

10+
The best way to use IObservable is to use one .Subscribe()-method which will take function parameters (which will be "injected" to the right place).
11+
12+
Use Rx (or R3) when you need async events to communicate with each other, e.g.:
13+
- Events, WebServices, Threads, Timers, AutoComplete, Drag & Drop, ...
14+

docsSrc/Tutorials/Getting_Started.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,51 @@ index: 1
77

88
# Getting Started
99

10+
To use the raw R3 from F# you would add first the NuGet package to R3:
11+
12+
[lang=bash]
13+
paket install R3
14+
15+
Then, this is a working sample:
16+
1017
```fsharp
11-
open FSharp.Control.R3
12-
let foo = ()
13-
let myAge = 21
14-
let color = Say.FavoriteColor.Red
18+
open System
19+
20+
// Create a bus
21+
use r3Bus = new R3.Subject<int> ()
22+
23+
// Filter events
24+
let interesting = R3.ObservableExtensions.Where (r3Bus, fun x -> x % 2 = 0)
25+
26+
// Subscribe to events
27+
let subscription =
28+
R3.ObservableExtensions.SubscribeAwait (
29+
interesting,
30+
fun i cancellationToken ->
31+
task {
32+
// Listen events
33+
printfn "%i" i
34+
return ()
35+
}
36+
|> System.Threading.Tasks.ValueTask
37+
)
38+
39+
// Publish some events
40+
[ 1..10 ] |> List.iter r3Bus.OnNext
1541
```
1642

17-
## Here is the path to downloading
43+
As you can see, this is nice, but a little bit noisy.
44+
This package will come top help.
45+
46+
Then you do:
1847

1948
[lang=bash]
2049
paket install FSharp.Control.R3
2150

51+
Now you have available functions like:
2252

53+
```fsharp
54+
open FSharp.Control.R3.Async
55+
56+
Observable.length r3Bus
57+
```

docsSrc/index.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22

33
---
44

5-
## What is FSharp.Control.R3?
5+
FSharp.Control.R3 provides F#-style modules for working with the [R3](https://github.com/Cysharp/R3).
66

7-
FSharp.Control.R3 is a library that does this specific thing.
7+
The fundamental problem with AsyncSeq is that the subscriber cannot say, "I've had enough; unsubscribe me, please".
88

9-
## Why use FSharp.Control.R3?
9+
The solution for this is [Reactive Extensions (Rx)](https://github.com/dotnet/reactive), which has an F# wrapper [FSharp.Control.Reactive](https://fsprojects.github.io/FSharp.Control.Reactive/).
1010

11-
I created it because I had to solve an issue with this other thing.
11+
R3 is a similar wrapper for [R3](https://github.com/Cysharp/R3), a re-implementation of Rx.
1212

1313
---
1414

15+
<div class="row">
16+
<div class="span1"></div>
17+
<div class="span6">
18+
<div class="well well-small" id="nuget">
19+
The FSharp.Control.R3 library can be <a href="https://nuget.org/packages/FSharp.Control.R3">installed from NuGet</a>:
20+
<pre>PM> Install-Package FSharp.Control.R3</pre>
21+
</div>
22+
</div>
23+
<div class="span1"></div>
24+
</div>
25+
26+
1527
<div class="row row-cols-1 row-cols-md-2">
1628
<div class="col mb-4">
1729
<div class="card h-100">

0 commit comments

Comments
 (0)