// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information. 

using System.Reactive.Disposables;

namespace System.Reactive.Linq.ObservableImpl
{
    #region [3,16]-ary

    /* The following code is generated by a T4 template. */

    #region CombineLatest auto-generated code (4/20/2017 3:38:14 PM)

    internal sealed class CombineLatest<T1, T2, T3, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly Func<T1, T2, T3, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, Func<T1, T2, T3, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, TResult> _resultSelector;

            public _(Func<T1, T2, T3, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(3, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3)
            {
                var subscriptions = new SingleAssignmentDisposable[3];
                for (int i = 0; i < 3; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly Func<T1, T2, T3, T4, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, Func<T1, T2, T3, T4, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(4, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4)
            {
                var subscriptions = new SingleAssignmentDisposable[4];
                for (int i = 0; i < 4; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly Func<T1, T2, T3, T4, T5, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, Func<T1, T2, T3, T4, T5, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(5, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5)
            {
                var subscriptions = new SingleAssignmentDisposable[5];
                for (int i = 0; i < 5; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly Func<T1, T2, T3, T4, T5, T6, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, Func<T1, T2, T3, T4, T5, T6, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(6, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6)
            {
                var subscriptions = new SingleAssignmentDisposable[6];
                for (int i = 0; i < 6; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(7, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7)
            {
                var subscriptions = new SingleAssignmentDisposable[7];
                for (int i = 0; i < 7; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(8, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8)
            {
                var subscriptions = new SingleAssignmentDisposable[8];
                for (int i = 0; i < 8; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(9, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9)
            {
                var subscriptions = new SingleAssignmentDisposable[9];
                for (int i = 0; i < 9; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(10, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10)
            {
                var subscriptions = new SingleAssignmentDisposable[10];
                for (int i = 0; i < 10; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(11, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11)
            {
                var subscriptions = new SingleAssignmentDisposable[11];
                for (int i = 0; i < 11; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly IObservable<T12> _source12;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _source12 = source12;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11, _source12);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(12, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;
            private CombineLatestObserver<T12> _observer12;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12)
            {
                var subscriptions = new SingleAssignmentDisposable[12];
                for (int i = 0; i < 12; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);
                _observer12 = new CombineLatestObserver<T12>(_gate, this, 11, subscriptions[11]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);
                subscriptions[11].Disposable = source12.SubscribeSafe(_observer12);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value, _observer12.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly IObservable<T12> _source12;
        private readonly IObservable<T13> _source13;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _source12 = source12;
            _source13 = source13;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11, _source12, _source13);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(13, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;
            private CombineLatestObserver<T12> _observer12;
            private CombineLatestObserver<T13> _observer13;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13)
            {
                var subscriptions = new SingleAssignmentDisposable[13];
                for (int i = 0; i < 13; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);
                _observer12 = new CombineLatestObserver<T12>(_gate, this, 11, subscriptions[11]);
                _observer13 = new CombineLatestObserver<T13>(_gate, this, 12, subscriptions[12]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);
                subscriptions[11].Disposable = source12.SubscribeSafe(_observer12);
                subscriptions[12].Disposable = source13.SubscribeSafe(_observer13);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value, _observer12.Value, _observer13.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly IObservable<T12> _source12;
        private readonly IObservable<T13> _source13;
        private readonly IObservable<T14> _source14;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _source12 = source12;
            _source13 = source13;
            _source14 = source14;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11, _source12, _source13, _source14);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(14, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;
            private CombineLatestObserver<T12> _observer12;
            private CombineLatestObserver<T13> _observer13;
            private CombineLatestObserver<T14> _observer14;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14)
            {
                var subscriptions = new SingleAssignmentDisposable[14];
                for (int i = 0; i < 14; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);
                _observer12 = new CombineLatestObserver<T12>(_gate, this, 11, subscriptions[11]);
                _observer13 = new CombineLatestObserver<T13>(_gate, this, 12, subscriptions[12]);
                _observer14 = new CombineLatestObserver<T14>(_gate, this, 13, subscriptions[13]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);
                subscriptions[11].Disposable = source12.SubscribeSafe(_observer12);
                subscriptions[12].Disposable = source13.SubscribeSafe(_observer13);
                subscriptions[13].Disposable = source14.SubscribeSafe(_observer14);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value, _observer12.Value, _observer13.Value, _observer14.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly IObservable<T12> _source12;
        private readonly IObservable<T13> _source13;
        private readonly IObservable<T14> _source14;
        private readonly IObservable<T15> _source15;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14, IObservable<T15> source15, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _source12 = source12;
            _source13 = source13;
            _source14 = source14;
            _source15 = source15;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11, _source12, _source13, _source14, _source15);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(15, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;
            private CombineLatestObserver<T12> _observer12;
            private CombineLatestObserver<T13> _observer13;
            private CombineLatestObserver<T14> _observer14;
            private CombineLatestObserver<T15> _observer15;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14, IObservable<T15> source15)
            {
                var subscriptions = new SingleAssignmentDisposable[15];
                for (int i = 0; i < 15; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);
                _observer12 = new CombineLatestObserver<T12>(_gate, this, 11, subscriptions[11]);
                _observer13 = new CombineLatestObserver<T13>(_gate, this, 12, subscriptions[12]);
                _observer14 = new CombineLatestObserver<T14>(_gate, this, 13, subscriptions[13]);
                _observer15 = new CombineLatestObserver<T15>(_gate, this, 14, subscriptions[14]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);
                subscriptions[11].Disposable = source12.SubscribeSafe(_observer12);
                subscriptions[12].Disposable = source13.SubscribeSafe(_observer13);
                subscriptions[13].Disposable = source14.SubscribeSafe(_observer14);
                subscriptions[14].Disposable = source15.SubscribeSafe(_observer15);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value, _observer12.Value, _observer13.Value, _observer14.Value, _observer15.Value);
        }
    }

    internal sealed class CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> : Producer<TResult, CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>._>
    {
        private readonly IObservable<T1> _source1;
        private readonly IObservable<T2> _source2;
        private readonly IObservable<T3> _source3;
        private readonly IObservable<T4> _source4;
        private readonly IObservable<T5> _source5;
        private readonly IObservable<T6> _source6;
        private readonly IObservable<T7> _source7;
        private readonly IObservable<T8> _source8;
        private readonly IObservable<T9> _source9;
        private readonly IObservable<T10> _source10;
        private readonly IObservable<T11> _source11;
        private readonly IObservable<T12> _source12;
        private readonly IObservable<T13> _source13;
        private readonly IObservable<T14> _source14;
        private readonly IObservable<T15> _source15;
        private readonly IObservable<T16> _source16;
        private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> _resultSelector;

        public CombineLatest(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14, IObservable<T15> source15, IObservable<T16> source16, Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> resultSelector)
        {
            _source1 = source1;
            _source2 = source2;
            _source3 = source3;
            _source4 = source4;
            _source5 = source5;
            _source6 = source6;
            _source7 = source7;
            _source8 = source8;
            _source9 = source9;
            _source10 = source10;
            _source11 = source11;
            _source12 = source12;
            _source13 = source13;
            _source14 = source14;
            _source15 = source15;
            _source16 = source16;
            _resultSelector = resultSelector;
        }

        protected override _ CreateSink(IObserver<TResult> observer, IDisposable cancel) => new _(_resultSelector, observer, cancel);

        protected override IDisposable Run(_ sink) => sink.Run(_source1, _source2, _source3, _source4, _source5, _source6, _source7, _source8, _source9, _source10, _source11, _source12, _source13, _source14, _source15, _source16);

        internal sealed class _ : CombineLatestSink<TResult>
        {
            private readonly Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> _resultSelector;

            public _(Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> resultSelector, IObserver<TResult> observer, IDisposable cancel)
                : base(16, observer, cancel)
            {
                _resultSelector = resultSelector;
            }

            private CombineLatestObserver<T1> _observer1;
            private CombineLatestObserver<T2> _observer2;
            private CombineLatestObserver<T3> _observer3;
            private CombineLatestObserver<T4> _observer4;
            private CombineLatestObserver<T5> _observer5;
            private CombineLatestObserver<T6> _observer6;
            private CombineLatestObserver<T7> _observer7;
            private CombineLatestObserver<T8> _observer8;
            private CombineLatestObserver<T9> _observer9;
            private CombineLatestObserver<T10> _observer10;
            private CombineLatestObserver<T11> _observer11;
            private CombineLatestObserver<T12> _observer12;
            private CombineLatestObserver<T13> _observer13;
            private CombineLatestObserver<T14> _observer14;
            private CombineLatestObserver<T15> _observer15;
            private CombineLatestObserver<T16> _observer16;

            public IDisposable Run(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, IObservable<T8> source8, IObservable<T9> source9, IObservable<T10> source10, IObservable<T11> source11, IObservable<T12> source12, IObservable<T13> source13, IObservable<T14> source14, IObservable<T15> source15, IObservable<T16> source16)
            {
                var subscriptions = new SingleAssignmentDisposable[16];
                for (int i = 0; i < 16; i++)
                    subscriptions[i] = new SingleAssignmentDisposable();

                _observer1 = new CombineLatestObserver<T1>(_gate, this, 0, subscriptions[0]);
                _observer2 = new CombineLatestObserver<T2>(_gate, this, 1, subscriptions[1]);
                _observer3 = new CombineLatestObserver<T3>(_gate, this, 2, subscriptions[2]);
                _observer4 = new CombineLatestObserver<T4>(_gate, this, 3, subscriptions[3]);
                _observer5 = new CombineLatestObserver<T5>(_gate, this, 4, subscriptions[4]);
                _observer6 = new CombineLatestObserver<T6>(_gate, this, 5, subscriptions[5]);
                _observer7 = new CombineLatestObserver<T7>(_gate, this, 6, subscriptions[6]);
                _observer8 = new CombineLatestObserver<T8>(_gate, this, 7, subscriptions[7]);
                _observer9 = new CombineLatestObserver<T9>(_gate, this, 8, subscriptions[8]);
                _observer10 = new CombineLatestObserver<T10>(_gate, this, 9, subscriptions[9]);
                _observer11 = new CombineLatestObserver<T11>(_gate, this, 10, subscriptions[10]);
                _observer12 = new CombineLatestObserver<T12>(_gate, this, 11, subscriptions[11]);
                _observer13 = new CombineLatestObserver<T13>(_gate, this, 12, subscriptions[12]);
                _observer14 = new CombineLatestObserver<T14>(_gate, this, 13, subscriptions[13]);
                _observer15 = new CombineLatestObserver<T15>(_gate, this, 14, subscriptions[14]);
                _observer16 = new CombineLatestObserver<T16>(_gate, this, 15, subscriptions[15]);

                subscriptions[0].Disposable = source1.SubscribeSafe(_observer1);
                subscriptions[1].Disposable = source2.SubscribeSafe(_observer2);
                subscriptions[2].Disposable = source3.SubscribeSafe(_observer3);
                subscriptions[3].Disposable = source4.SubscribeSafe(_observer4);
                subscriptions[4].Disposable = source5.SubscribeSafe(_observer5);
                subscriptions[5].Disposable = source6.SubscribeSafe(_observer6);
                subscriptions[6].Disposable = source7.SubscribeSafe(_observer7);
                subscriptions[7].Disposable = source8.SubscribeSafe(_observer8);
                subscriptions[8].Disposable = source9.SubscribeSafe(_observer9);
                subscriptions[9].Disposable = source10.SubscribeSafe(_observer10);
                subscriptions[10].Disposable = source11.SubscribeSafe(_observer11);
                subscriptions[11].Disposable = source12.SubscribeSafe(_observer12);
                subscriptions[12].Disposable = source13.SubscribeSafe(_observer13);
                subscriptions[13].Disposable = source14.SubscribeSafe(_observer14);
                subscriptions[14].Disposable = source15.SubscribeSafe(_observer15);
                subscriptions[15].Disposable = source16.SubscribeSafe(_observer16);

                return StableCompositeDisposable.Create(subscriptions);
            }

            protected override TResult GetResult() => _resultSelector(_observer1.Value, _observer2.Value, _observer3.Value, _observer4.Value, _observer5.Value, _observer6.Value, _observer7.Value, _observer8.Value, _observer9.Value, _observer10.Value, _observer11.Value, _observer12.Value, _observer13.Value, _observer14.Value, _observer15.Value, _observer16.Value);
        }
    }


    #endregion

    #endregion
}
