Created
July 8, 2022 15:51
-
-
Save andybrackley/243278763578a5dcee629a7662924a54 to your computer and use it in GitHub Desktop.
Observable Scan Implementation.
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<T> MyScan<T>(this IObservable<T> stream, T init, Func<(T acc, T curr), T> resultCalc) | |
{ | |
return Observable.Create<T>(obs => | |
{ | |
var result = init; | |
var dispose = | |
stream.Subscribe( | |
x => { | |
result = resultCalc((result, x)); | |
obs.OnNext(result); | |
}, | |
obs.OnError, | |
obs.OnComplete | |
); | |
return() => { dispose.Dispose(); }; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment