package D1;

import java.util.Iterator;
import java.util.NoSuchElementException;

/* JADX INFO: loaded from: classes.dex */
final class e implements f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final y1.a f505a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final y1.l f506b;

    public static final class a implements Iterator, z1.a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private Object f507b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private int f508g = -2;

        a() {
        }

        private final void a() {
            Object objInvoke;
            if (this.f508g == -2) {
                objInvoke = e.this.f505a.invoke();
            } else {
                y1.l lVar = e.this.f506b;
                Object obj = this.f507b;
                kotlin.jvm.internal.l.b(obj);
                objInvoke = lVar.invoke(obj);
            }
            this.f507b = objInvoke;
            this.f508g = objInvoke == null ? 0 : 1;
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            if (this.f508g < 0) {
                a();
            }
            return this.f508g == 1;
        }

        @Override // java.util.Iterator
        public Object next() {
            if (this.f508g < 0) {
                a();
            }
            if (this.f508g == 0) {
                throw new NoSuchElementException();
            }
            Object obj = this.f507b;
            kotlin.jvm.internal.l.c(obj, "null cannot be cast to non-null type T of kotlin.sequences.GeneratorSequence");
            this.f508g = -1;
            return obj;
        }

        @Override // java.util.Iterator
        public void remove() {
            throw new UnsupportedOperationException("Operation is not supported for read-only collection");
        }
    }

    public e(y1.a getInitialValue, y1.l getNextValue) {
        kotlin.jvm.internal.l.e(getInitialValue, "getInitialValue");
        kotlin.jvm.internal.l.e(getNextValue, "getNextValue");
        this.f505a = getInitialValue;
        this.f506b = getNextValue;
    }

    @Override // D1.f
    public Iterator iterator() {
        return new a();
    }
}
