Skip to content

Commit 26b4a32

Browse files
committed
📝 Add minimal code example in Usage section
1 parent b068949 commit 26b4a32

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ the bare essentials for source-only inclusion, with `Subject<T>` being pretty mu
2222
the same).
2323
For example: [Using Subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)).
2424

25+
```csharp
26+
using System;
27+
28+
var subject = new Subject<string>();
29+
30+
subject.Subscribe(x => Console.WriteLine($"Got raw value {x}"));
31+
32+
subject.Where(x => int.TryParse(x, out _))
33+
.Select(x => int.Parse(x))
34+
.Subscribe(x => Console.WriteLine($"Got number {x} (squared is {x * x})"));
35+
36+
subject.Where(x => bool.TryParse(x, out var value) && value)
37+
.Subscribe(x => Console.WriteLine($"Got a boolean True"));
38+
39+
while (Console.ReadLine() is var line && !string.IsNullOrEmpty(line))
40+
subject.OnNext(line);
41+
```
42+
2543
# Why
2644

2745
For the most part, a producer needs the `Subject<T>` (read more about

src/RxFree/readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ the bare essentials for source-only inclusion, with `Subject<T>` being pretty mu
1616
the same).
1717
For example: [Using Subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)).
1818

19+
```csharp
20+
using System;
21+
22+
var subject = new Subject<string>();
23+
24+
subject.Subscribe(x => Console.WriteLine($"Got raw value {x}"));
25+
26+
subject.Where(x => int.TryParse(x, out _))
27+
.Select(x => int.Parse(x))
28+
.Subscribe(x => Console.WriteLine($"Got number {x} (squared is {x * x})"));
29+
30+
subject.Where(x => bool.TryParse(x, out var value) && value)
31+
.Subscribe(x => Console.WriteLine($"Got a boolean True"));
32+
33+
while (Console.ReadLine() is var line && !string.IsNullOrEmpty(line))
34+
subject.OnNext(line);
35+
```
36+
1937
# Why
2038

2139
For the most part, a producer needs the `Subject<T>` (read more about

0 commit comments

Comments
 (0)