Created
May 10, 2012 23:06
-
-
Save andersonimes/2656478 to your computer and use it in GitHub Desktop.
[Rx]Extensions for tagging an event stream. Useful for when you need to combine two observables and can't use anonymous types
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 class ObservableMixins | |
{ | |
public static IObservable<ObjectTag<T, V>> Tag<T, V>(this IObservable<V> sequenceToTag, T tag) | |
{ | |
return sequenceToTag.Tag(_ => tag); | |
} | |
public static IObservable<ObjectTag<T, V>> Tag<T, V>(this IObservable<V> sequenceToTag, Func<V, T> tagFunction) | |
{ | |
return sequenceToTag.Select(v => new ObjectTag<T, V>(tagFunction(v), v)); | |
} | |
} | |
public class ObjectTag<T, J> | |
{ | |
public T Tag { get; private set; } | |
public J Value { get; private set; } | |
public ObjectTag(T tag, J val) | |
{ | |
Tag = tag; | |
Value = val; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment