Created
February 13, 2017 19:44
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Returns the elements from the source observable sequence only after the predicate returns true (non-inclusive) | |
/// </summary> | |
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam> | |
/// <param name="source">Source sequence to propagate elements for</param> | |
/// <param name="predicate">A function to test each source element for a condition</param> | |
/// <returns>An observable sequence containing the elements of the source sequence starting from the point the predicate is true</returns> | |
[NotNull] | |
public static IObservable<TSource> SkipUntil<TSource>([NotNull] this IObservable<TSource> source, [NotNull] Func<TSource, bool> predicate) | |
{ | |
if (source == null) | |
throw new ArgumentNullException(nameof(source)); | |
if (predicate == null) | |
throw new ArgumentNullException(nameof(predicate)); | |
return source.Publish(s => s.SkipUntil(s.Where(predicate))); | |
} | |
/// <summary> | |
/// Returns the elements from the source observable sequence until the predicate returns true (inclusive) | |
/// </summary> | |
/// <typeparam name="TSource">The type of the elements in the source sequence</typeparam> | |
/// <param name="source">Source sequence to propagate elements for</param> | |
/// <param name="predicate">A function to test each source element for a condition</param> | |
/// <returns>An observable sequence that contains elements from the input sequence until the condition is met</returns> | |
[NotNull] | |
public static IObservable<TSource> TakeUntil<TSource>([NotNull] this IObservable<TSource> source, [NotNull] Func<TSource, bool> predicate) | |
{ | |
if (source == null) | |
throw new ArgumentNullException(nameof(source)); | |
if (predicate == null) | |
throw new ArgumentNullException(nameof(predicate)); | |
return source.Publish(s => s.TakeUntil(s.SkipUntil(predicate))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment