package rp;

import java.util.Iterator;
import java.util.NoSuchElementException;
import kotlin.jvm.internal.t;

/* loaded from: classes3.dex */
public final class q implements h {

    /* renamed from: a, reason: collision with root package name */
    private final h f35076a;

    /* renamed from: b, reason: collision with root package name */
    private final dn.l f35077b;

    /* loaded from: classes3.dex */
    public static final class a implements Iterator, en.a {

        /* renamed from: p, reason: collision with root package name */
        private final Iterator f35078p;

        /* renamed from: q, reason: collision with root package name */
        private int f35079q = -1;

        /* renamed from: r, reason: collision with root package name */
        private Object f35080r;

        a() {
            this.f35078p = q.this.f35076a.iterator();
        }

        private final void a() {
            if (this.f35078p.hasNext()) {
                Object next = this.f35078p.next();
                if (((Boolean) q.this.f35077b.invoke(next)).booleanValue()) {
                    this.f35079q = 1;
                    this.f35080r = next;
                    return;
                }
            }
            this.f35079q = 0;
        }

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

        @Override // java.util.Iterator
        public Object next() {
            if (this.f35079q == -1) {
                a();
            }
            if (this.f35079q == 0) {
                throw new NoSuchElementException();
            }
            Object obj = this.f35080r;
            this.f35080r = null;
            this.f35079q = -1;
            return obj;
        }

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

    public q(h sequence, dn.l predicate) {
        t.g(sequence, "sequence");
        t.g(predicate, "predicate");
        this.f35076a = sequence;
        this.f35077b = predicate;
    }

    @Override // rp.h
    public Iterator iterator() {
        return new a();
    }
}
