Show / Hide Table of Contents

Class ObservableExtensions

Extension methods for System.IObservable<T>.
Inheritance
System.Object
ObservableExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Annex.Reactive.Linq
Assembly: Annex.Reactive.dll
Syntax
[PublicAPI]
public static class ObservableExtensions

Methods

| Improve this Doc View Source

Inverse(IObservable<Boolean>)

Inverts the source sequence. Equivalent to @this.Select(@bool => !@bool).
Declaration
[Pure]
[NotNull]
public static IObservable<bool> Inverse([NotNull] this IObservable<bool> this)
Parameters
Type Name Description
System.IObservable<System.Boolean> this The source sequence.
Returns
Type Description
System.IObservable<System.Boolean> The inverse of the source sequence.
Examples
await Observable.Return(true).Inverse(); // false
Exceptions
Type Condition
System.ArgumentNullException this is null.
| Improve this Doc View Source

RepeatAfterDelay<T>(IObservable<T>, TimeSpan, IScheduler)

Repeats the source sequence after the specified delay.
Declaration
[Pure]
[NotNull]
public static IObservable<T> RepeatAfterDelay<T>([NotNull] this IObservable<T> this, TimeSpan delay, [NotNull] IScheduler scheduler)
Parameters
Type Name Description
System.IObservable<T> this The source sequence.
System.TimeSpan delay The time to wait until repeating.
System.Reactive.Concurrency.IScheduler scheduler The scheduler for the delay.
Returns
Type Description
System.IObservable<T> A delayed, repeating sequence based on the source.
Type Parameters
Name Description
T The type of elements in the sequence.
Examples
Observable.Return(Unit.Default)
    .RepeatAfterDelay(TimeSpan.FromSeconds(30), Scheduler.Default)
    .Subscribe(_ => Console.WriteLine("Ping"));

// 0s: Ping
// 30s: Ping
// 60s: Ping
// (infinite)
Exceptions
Type Condition
System.ArgumentNullException this or scheduler is null.
See Also
Adapted from StackOverflow
| Improve this Doc View Source

SwitchIfEmpty<T>(IObservable<T>, IObservable<T>)

Switches to the provided sequence if the source sequence is empty.
Declaration
[Pure]
[NotNull]
public static IObservable<T> SwitchIfEmpty<T>([NotNull] this IObservable<T> this, [NotNull] IObservable<T> switchTo)
Parameters
Type Name Description
System.IObservable<T> this The source sequence.
System.IObservable<T> switchTo The sequence to switch to if the source sequence is empty.
Returns
Type Description
System.IObservable<T> The source sequence if it is not empty, otherwise the secondary sequence.
Type Parameters
Name Description
T The type of elements in the source sequence.
Examples
await Observable.Empty<string>().SwitchIfEmpty(Observable.Return("Fallback")); // Fallback

await Observable.Return("First").SwitchIfEmpty(Observable.Return("Fallback")); // First
Exceptions
Type Condition
System.ArgumentNullException this or switchTo is null.
See Also
Adapted from StackOverflow
| Improve this Doc View Source

ToDictionary<TKey, TValue>(IObservable<(TKey Key, TValue Value)>)

Creates a dictionary from an observable sequence contain tuple key/value pairs.
Declaration
[Pure]
[NotNull]
public static IObservable<IDictionary<TKey, TValue>> ToDictionary<TKey, TValue>([NotNull] this IObservable<(TKey Key, TValue Value)> this)
Parameters
Type Name Description
System.IObservable<System.ValueTuple<TKey, TValue>> this The source sequence.
Returns
Type Description
System.IObservable<System.Collections.Generic.IDictionary<TKey, TValue>> A dictionary created from the source sequence.
Type Parameters
Name Description
TKey The type of the dictionary key.
TValue The type of the dictionary value.
Examples
var dict = await Observable.Return(("Key1", "Value1")).ToDictionary();

dict["Key1"]; // Value1
Exceptions
Type Condition
System.ArgumentNullException this is null.
| Improve this Doc View Source

VoidElements<T>(IObservable<T>)

Voids all elements in the sequence. Equivalent to @this.Select(_ => Unit.Default).
Declaration
[Pure]
[NotNull]
public static IObservable<Unit> VoidElements<T>([NotNull] this IObservable<T> this)
Parameters
Type Name Description
System.IObservable<T> this The source sequence.
Returns
Type Description
System.IObservable<System.Reactive.Unit> The source sequence with its elements voided.
Type Parameters
Name Description
T The type of elements in the sequence.
Examples
Observable.Interval(TimeSpan.FromMinutes(5))
    .VoidElements()
    .Subscribe(Console.WriteLine);

// 5m: Unit
// 10m: Unit
// etc.
Exceptions
Type Condition
System.ArgumentNullException this is null.
| Improve this Doc View Source

VoidTerminations<T>(IObservable<T>)

Materializes only the termination notifications of the source sequence and voids all resulting elements.
Declaration
[Pure]
[NotNull]
public static IObservable<Unit> VoidTerminations<T>([NotNull] this IObservable<T> this)
Parameters
Type Name Description
System.IObservable<T> this The source sequence.
Returns
Type Description
System.IObservable<System.Reactive.Unit> An observable sequence whose elements are voided termination notifications of the source sequence.
Type Parameters
Name Description
T The type of the elements in the source sequence.
Examples
await Observable.Return("Value").VoidTerminations(); // Unit
await Observable.Empty<string>().VoidTerminations(); // Unit
await Observable.Throw<string>(new Exception()).VoidTerminations(); // Unit
Exceptions
Type Condition
System.ArgumentNullException this is null.
  • Improve this Doc
  • View Source
Back to top Copyright © George Taylor Buchanan
Generated by DocFX