Created
May 8, 2015 15:49
-
-
Save mattbarrett/f2bd907e5ca89eca13e4 to your computer and use it in GitHub Desktop.
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
public static IObservable<TResult> WithLatestFrom<TFirst, TSecond, TResult>(this IObservable<TFirst> first, IObservable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector) | |
{ | |
if (first == null) | |
throw new ArgumentNullException("first"); | |
if (second == null) | |
throw new ArgumentNullException("second"); | |
if (resultSelector == null) | |
throw new ArgumentNullException("resultSelector"); | |
return first.Publish(f => | |
{ | |
return second.Publish(s => | |
{ | |
return Observable.CombineLatest( | |
f.SkipUntil(s), | |
s, | |
Tuple.Create) | |
.TakeUntil(f.Materialize().Where(n => n.Kind == NotificationKind.OnCompleted)) | |
.DistinctUntilChanged(tp => tp.Item1) | |
.Select(tp => resultSelector(tp.Item1, tp.Item2)); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment