From 26b4a3263c4e6857def5b003973dd0c35b98d882 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Wed, 22 Sep 2021 05:52:20 -0300 Subject: [PATCH] :memo: Add minimal code example in Usage section --- readme.md | 18 ++++++++++++++++++ src/RxFree/readme.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/readme.md b/readme.md index 647450c..eb4e78b 100644 --- a/readme.md +++ b/readme.md @@ -22,6 +22,24 @@ the bare essentials for source-only inclusion, with `Subject` 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(); + +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` (read more about diff --git a/src/RxFree/readme.md b/src/RxFree/readme.md index c5759f6..7e7f764 100644 --- a/src/RxFree/readme.md +++ b/src/RxFree/readme.md @@ -16,6 +16,24 @@ the bare essentials for source-only inclusion, with `Subject` 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(); + +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` (read more about