From f96fada6b8d8f83b5dfbcfff43826d42c508aad9 Mon Sep 17 00:00:00 2001 From: Chris Froussios Date: Mon, 6 Jul 2015 17:19:29 +0200 Subject: [PATCH] Better runnable examples --- .../Chapter2/Creating/SimpleFactories.cs | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Examples/Examples/Chapter2/Creating/SimpleFactories.cs b/Examples/Examples/Chapter2/Creating/SimpleFactories.cs index c2d8cb0..2849c1a 100644 --- a/Examples/Examples/Chapter2/Creating/SimpleFactories.cs +++ b/Examples/Examples/Chapter2/Creating/SimpleFactories.cs @@ -10,51 +10,51 @@ namespace IntroToRx.Examples { class SimpleFactories { - //TODO: improve format - public void ExampleReturn() { var singleValue = Observable.Return("Value"); - //which could have also been simulated with a replay subject - var subject = new ReplaySubject(); - subject.OnNext("Value"); - subject.OnCompleted(); - singleValue.Subscribe(Console.WriteLine); - + singleValue.Subscribe( + Console.WriteLine, + Console.WriteLine, + () => Console.WriteLine("Completed")); + //Value + //Completed } public void ExampleEmpty() { var empty = Observable.Empty(); - //Behaviorally equivalent to - var subject = new ReplaySubject(); - subject.OnCompleted(); - empty.Subscribe(Console.WriteLine); + empty.Subscribe( + Console.WriteLine, + Console.WriteLine, + () => Console.WriteLine("Completed")); + + //Completed } public void ExampleNever() { var never = Observable.Never(); - //similar to a subject without notifications - var subject = new Subject(); - never.Subscribe(Console.WriteLine); + never.Subscribe( + Console.WriteLine, + Console.WriteLine, + () => Console.WriteLine("Completed")); + + // } public void ExampleThrow() { var throws = Observable.Throw(new Exception()); - //Behaviorally equivalent to - var subject = new ReplaySubject(); - subject.OnError(new Exception()); throws.Subscribe( Console.WriteLine, Console.WriteLine, - Console.WriteLine); + () => Console.WriteLine("Completed")); //System.Exception: Exception of type 'System.Exception' was thrown. }