Skip to content

Instantly share code, notes, and snippets.

@andybrackley
Created July 8, 2022 15:51
Show Gist options
  • Save andybrackley/243278763578a5dcee629a7662924a54 to your computer and use it in GitHub Desktop.
Save andybrackley/243278763578a5dcee629a7662924a54 to your computer and use it in GitHub Desktop.
Observable Scan Implementation.
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