diff --git a/Part 2 - Sequence Basics/5. Transformation of sequences.md b/Part 2 - Sequence Basics/5. Transformation of sequences.md index 5790e52..d3e31c8 100644 --- a/Part 2 - Sequence Basics/5. Transformation of sequences.md +++ b/Part 2 - Sequence Basics/5. Transformation of sequences.md @@ -47,7 +47,7 @@ Output: While this can be useful, more common use is to transform values from one type to another. In this example we transform integer values to characters. ```C# -Observable.Range(1, 5); +Observable.Range(1, 5) .Select(i =>(char)(i + 64)) .Dump("char"); ``` @@ -315,7 +315,7 @@ This last example better illustrates how `SelectMany` can take a single value an ```C# Func letter = i => (char)(i + 64); Observable.Return(1) - .SelectMany(i => Observable.Return(letter(i))); + .SelectMany(i => Observable.Return(letter(i))) .Dump("SelectMany"); ``` diff --git a/Part 3 - Taming the sequence/1. Side effects.md b/Part 3 - Taming the sequence/1. Side effects.md index ef09a1a..d4467f4 100644 --- a/Part 3 - Taming the sequence/1. Side effects.md +++ b/Part 3 - Taming the sequence/1. Side effects.md @@ -322,8 +322,8 @@ The class now looks much better. The improvement, however, is only cosmetic. The ```C# var repo = new ObscuredLeakinessLetterRepo(); -var good = repo.GetLetters(); -var evil = repo.GetLetters(); +var good = repo.Letters; +var evil = repo.Letters; good.Subscribe( Console.WriteLine); //Be naughty @@ -350,9 +350,9 @@ C The fix to this problem is quite simple. By applying the `AsObservable` extension method, the _letters field will be wrapped in a type that only implements IObservable. ```C# -public IObservable GetLetters() +public IObservable Letters { - return _letters.AsObservable(); + get { return _letters.AsObservable(); } } ``` diff --git a/Part 3 - Taming the sequence/3. Advanced error handling.md b/Part 3 - Taming the sequence/3. Advanced error handling.md index 044d454..018b254 100644 --- a/Part 3 - Taming the sequence/3. Advanced error handling.md +++ b/Part 3 - Taming the sequence/3. Advanced error handling.md @@ -43,7 +43,7 @@ Here S1 represents the first sequence that ends with an error (X). S2 is the con ```C# var source = new Subject(); var result = source.Catch(Observable.Empty()); -result.Dump("Catch");); +result.Dump("Catch"); source.OnNext(1); source.OnNext(2); source.OnError(new Exception("Fail!")); diff --git a/Part 3 - Taming the sequence/4. Combining sequences.md b/Part 3 - Taming the sequence/4. Combining sequences.md index c034857..2f507f7 100644 --- a/Part 3 - Taming the sequence/4. Combining sequences.md +++ b/Part 3 - Taming the sequence/4. Combining sequences.md @@ -559,8 +559,8 @@ var systemStatus = webServerStatus .CombineLatest( databaseStatus, (webStatus, dbStatus) => webStatus && dbStatus) - .DistinctUntilChanged() - .StartWith(false); + .StartWith(false) + .DistinctUntilChanged(); ``` ### Zip @@ -680,7 +680,7 @@ It may sound very complex, but comparing some code samples should make it easier To `Zip` three sequences together, you can either use Zip methods chained together like this: -```C#` +```C# var one = Observable.Interval(TimeSpan.FromSeconds(1)).Take(5); var two = Observable.Interval(TimeSpan.FromMilliseconds(250)).Take(10); var three = Observable.Interval(TimeSpan.FromMilliseconds(150)).Take(14); diff --git a/Part 3 - Taming the sequence/5. Time-shifted sequences.md b/Part 3 - Taming the sequence/5. Time-shifted sequences.md index ad209c9..38cef2e 100644 --- a/Part 3 - Taming the sequence/5. Time-shifted sequences.md +++ b/Part 3 - Taming the sequence/5. Time-shifted sequences.md @@ -279,21 +279,18 @@ To illustrate this we will create a buffering scheme where we open a new buffer ```C# Observable.Interval(TimeSpan.FromMilliseconds(100)) .Buffer( - Observable.Interval(TimeSpan.FromMilliseconds(100)) - .Select(i => i+1) - .StartWith(0), // emit "0" at time 0 + Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(100)), (v) => Observable.Timer(TimeSpan.FromMilliseconds(100 * v))) .Subscribe(b => Console.WriteLine(String.Join(", ", b))); ``` Output ``` -0 -1, 2 -2, 3, 4 -3, 4, 5, 6 -4, 5, 6, 7, 8 -5, 6, 7, 8, 9, 10 +1 +2, 3 +3, 4, 5 +4, 5, 6, 7 +5, 6, 7, 8, 9 ... ``` @@ -313,7 +310,7 @@ x --------------------x ``` -Note that running such time-sensitive examples will probably produce similar but different results than what we present here, because timed operations in C# are not guaranteed to be accurate. +Note that running such time-sensitive examples will probably produce similar but different results than what we present here, because timed operations in C# are not guaranteed to be accurate. Even theoretically, there are limitations to timed scheduling: looking at the first marble diagram, should the second buffer include `0`, `1` or both? It touches both events, but it just happens here that the scheduled opening of the buffer is executed immediately after the emission of onNext in the source. ## Delay @@ -525,7 +522,7 @@ public static IObservable Timeout( If we provide a `TimeSpan` and no values are produced within that time span, then the sequence fails with a `TimeoutException`. ```C# -var source = Observable.Interval(TimeSpan.FromMilliseconds(100)).Take(10) +var source = Observable.Interval(TimeSpan.FromMilliseconds(100)).Take(5) .Concat(Observable.Interval(TimeSpan.FromSeconds(2))); var timeout = source.Timeout(TimeSpan.FromSeconds(1)); timeout.Subscribe( diff --git a/Part 3 - Taming the sequence/6. Hot and Cold observables.md b/Part 3 - Taming the sequence/6. Hot and Cold observables.md index 0265eda..7dcb01b 100644 --- a/Part 3 - Taming the sequence/6. Hot and Cold observables.md +++ b/Part 3 - Taming the sequence/6. Hot and Cold observables.md @@ -136,7 +136,7 @@ public void SimpleColdSample() var period = TimeSpan.FromSeconds(1); var observable = Observable.Interval(period); observable.Subscribe(i => Console.WriteLine("first subscription : {0}", i)); - Thread.Sleep(period); + Thread.Sleep(period + TimeSpan.FromMilliseconds(50)); observable.Subscribe(i => Console.WriteLine("second subscription : {0}", i)); Console.ReadKey(); /* Output: @@ -160,7 +160,7 @@ var period = TimeSpan.FromSeconds(1); var observable = Observable.Interval(period).Publish(); observable.Connect(); observable.Subscribe(i => Console.WriteLine("first subscription : {0}", i)); -Thread.Sleep(period); +Thread.Sleep(period + TimeSpan.FromMilliseconds(50)); observable.Subscribe(i => Console.WriteLine("second subscription : {0}", i)); ``` @@ -179,7 +179,7 @@ In the example above, the observable variable is an `IConnectableObservable`, var period = TimeSpan.FromSeconds(1); var observable = Observable.Interval(period).Publish(); observable.Subscribe(i => Console.WriteLine("first subscription : {0}", i)); -Thread.Sleep(period); +Thread.Sleep(period + TimeSpan.FromMilliseconds(50)); observable.Subscribe(i => Console.WriteLine("second subscription : {0}", i)); observable.Connect(); ``` @@ -343,11 +343,11 @@ Output: Press any key to subscribe Publishing 0 Publishing 1 -Press any key to unsubscribe. Publishing 2 Publishing 3 +Press any key to unsubscribe. Publishing 4 -subscription : 4 +subscription: 4 Press any key to exit. ```