<PackageReference Include="System.Reactive" Version="4.4.1" />

Scan<TSource>

sealed class Scan<TSource> : Producer<TSource, _<TSource>>
namespace System.Reactive.Linq.ObservableImpl { internal sealed class Scan<TSource> : Producer<TSource, Scan<TSource>._> { internal sealed class _ : IdentitySink<TSource> { private readonly Func<TSource, TSource, TSource> _accumulator; private TSource _accumulation; private bool _hasAccumulation; public _(Func<TSource, TSource, TSource> accumulator, IObserver<TSource> observer) : base(observer) { _accumulator = accumulator; } public override void OnNext(TSource value) { try { if (_hasAccumulation) _accumulation = _accumulator(_accumulation, value); else { _accumulation = value; _hasAccumulation = true; } } catch (Exception error) { ForwardOnError(error); return; } ForwardOnNext(_accumulation); } } private readonly IObservable<TSource> _source; private readonly Func<TSource, TSource, TSource> _accumulator; public Scan(IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator) { _source = source; _accumulator = accumulator; } protected override _ CreateSink(IObserver<TSource> observer) { return new _(_accumulator, observer); } protected override void Run(_ sink) { sink.Run(_source); } } }