Skip to content

Commit

Permalink
📝 Add minimal code example in Usage section
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Sep 22, 2021
1 parent b068949 commit 26b4a32
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ the bare essentials for source-only inclusion, with `Subject<T>` being pretty mu
the same).
For example: [Using Subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)).

```csharp
using System;

var subject = new Subject<string>();

subject.Subscribe(x => Console.WriteLine($"Got raw value {x}"));

subject.Where(x => int.TryParse(x, out _))
.Select(x => int.Parse(x))
.Subscribe(x => Console.WriteLine($"Got number {x} (squared is {x * x})"));

subject.Where(x => bool.TryParse(x, out var value) && value)
.Subscribe(x => Console.WriteLine($"Got a boolean True"));

while (Console.ReadLine() is var line && !string.IsNullOrEmpty(line))
subject.OnNext(line);
```

# Why

For the most part, a producer needs the `Subject<T>` (read more about
Expand Down
18 changes: 18 additions & 0 deletions src/RxFree/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ the bare essentials for source-only inclusion, with `Subject<T>` being pretty mu
the same).
For example: [Using Subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)).

```csharp
using System;

var subject = new Subject<string>();

subject.Subscribe(x => Console.WriteLine($"Got raw value {x}"));

subject.Where(x => int.TryParse(x, out _))
.Select(x => int.Parse(x))
.Subscribe(x => Console.WriteLine($"Got number {x} (squared is {x * x})"));

subject.Where(x => bool.TryParse(x, out var value) && value)
.Subscribe(x => Console.WriteLine($"Got a boolean True"));

while (Console.ReadLine() is var line && !string.IsNullOrEmpty(line))
subject.OnNext(line);
```

# Why

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

0 comments on commit 26b4a32

Please sign in to comment.