From 87830303ae2777a4e5ae756da1f65be948e3a686 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sat, 11 Jun 2022 13:18:12 -0500 Subject: [PATCH] chore: Add NotNull extension method for IObservable The main purpose of this is to force type `T` to not be nullable. If you just use `Where()`, then you still get `IObservable`. --- src/Common/Extensions/RxExtensions.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Common/Extensions/RxExtensions.cs b/src/Common/Extensions/RxExtensions.cs index bdc1575d..b1088732 100644 --- a/src/Common/Extensions/RxExtensions.cs +++ b/src/Common/Extensions/RxExtensions.cs @@ -43,4 +43,11 @@ public static class RxExtensions } }); } + + // Borrowed from: https://stackoverflow.com/a/59434717/157971 + public static IObservable NotNull(this IObservable observable) + where T : class + { + return observable.Where(x => x is not null).Select(x => x!); + } }