Skip to content

Instantly share code, notes, and snippets.

@mattbarrett
Created May 8, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbarrett/f2bd907e5ca89eca13e4 to your computer and use it in GitHub Desktop.
Save mattbarrett/f2bd907e5ca89eca13e4 to your computer and use it in GitHub Desktop.
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