Skip to content

Commit

Permalink
slightly better string handling extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstonis committed Dec 31, 2023
1 parent a3a43a1 commit d3c17f9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Stellar/Extensions/IObservableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,24 @@ public static IObservable<TSource> IsNotDefault<TSource>(this IObservable<TSourc
return source.Where(x => x.HasValue && EqualityComparer<T>.Default.Equals(x.Value, comparison));
}

public static IObservable<string> IsNotNullOrEmpty(this IObservable<string> source)
public static IObservable<string> IsNotEmpty(this IObservable<string> source)
{
return source.Where(static str => !string.IsNullOrEmpty(str));
}

public static IObservable<string> IsNotNullOrEmpty(this IObservable<string?> source)
{
return source.Where(static str => !string.IsNullOrEmpty(str))
.Select(str => str!);
}

public static IObservable<string> IsNotNull(this IObservable<string?> source)
{
return source
.Where(static str => str is not null)
.Select(str => str!);
}

public static IObservable<T> GetValueOrDefault<T>(this IObservable<T?> source, T defaultValue = default(T))
where T : struct
{
Expand Down Expand Up @@ -525,4 +538,4 @@ public static IObservable<T> ObserveLatestOn<T>(this IObservable<T> source, ISch
.TakeUntil(o.IgnoreElements().Concat(Observable.Return(default(T), schedulerOrDefault)));
});
}
}
}

0 comments on commit d3c17f9

Please sign in to comment.