Skip to content

Commit ebab5fc

Browse files
lukkeaidg10HowardvanRooijen
authored
Update 02_KeyTypes.md (#2189)
* Update 02_KeyTypes.md Correct typo that said: "Remember when I said that in an abstract sense, IObserver<T> represents the same thing as IEnumerable<T>?" to: "Remember when I said that in an abstract sense, IObserver<T> represents the same thing as IEnumerator<T>?" * Update Rx.NET/Documentation/IntroToRx/02_KeyTypes.md The intent of the original suggestion was correct, but added a new type, which this fixes Co-authored-by: Howard van Rooijen <[email protected]> --------- Co-authored-by: Ian Griffiths <[email protected]> Co-authored-by: Howard van Rooijen <[email protected]>
1 parent 31a5ca5 commit ebab5fc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Rx.NET/Documentation/IntroToRx/02_KeyTypes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ If you're wondering whether the relationship between `IObservable<T>` and `IObse
287287

288288
The difference reflects the fundamental _pull vs push_ difference between `IEnumerable<T>` and `IObservable<T>`. Whereas with `IEnumerable<T>` we ask the source to create an `IEnumerator<T>` for us which we can then use to retrieve items (which is what a C# `foreach` loop does), with `IObservable<T>`, the source does not _implement_ `IObserver<T>`: it expects _us_ to supply an `IObserver<T>` and it will then push its values into that observer.
289289

290-
So why does `IObserver<T>` have these three methods? Remember when I said that in an abstract sense, `IObserver<T>` represents the same thing as `IEnumerable<T>`? I meant it. It might be an abstract sense, but it is precise: `IObservable<T>` and `IObserver<T>` were designed to preserve the exact meaning of `IEnumerable<T>` and `IEnumerator<T>`, changing only the detailed mechanism of consumption.
290+
So why does `IObserver<T>` have these three methods? Remember when I said that in an abstract sense, `IObserver<T>` represents the same thing as `IEnumerator<T>`? I meant it. It might be an abstract sense, but it is precise: `IObservable<T>` and `IObserver<T>` were designed to preserve the exact meaning of `IEnumerable<T>` and `IEnumerator<T>`, changing only the detailed mechanism of consumption.
291291

292292
To see what that means, think about what happens when you iterate over an `IEnumerable<T>` (with, say, a `foreach` loop). With each iteration (and more precisely, on each call to the enumerator's [`MoveNext`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.ienumerator.movenext) method) there are three things that could happen:
293293

@@ -581,4 +581,4 @@ What if we unsubscribe early by calling `subscription.Dispose()`? In that case i
581581

582582
Either way, everything from the source to the observer, including any operators that were sitting in between, gets shut down.
583583

584-
Now that we understand the relationship between an `IObservable<T>` source and the `IObserver<T>` interface that received event notifications, we can look at how we might create an `IObservable<T>` instance to represent events of interest in our application.
584+
Now that we understand the relationship between an `IObservable<T>` source and the `IObserver<T>` interface that received event notifications, we can look at how we might create an `IObservable<T>` instance to represent events of interest in our application.

0 commit comments

Comments
 (0)