package rp;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import sm.c0;
import sm.u;
import sm.y;

/* loaded from: classes3.dex */
public abstract class p extends o {

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

        /* renamed from: p */
        final /* synthetic */ h f35071p;

        public a(h hVar) {
            this.f35071p = hVar;
        }

        @Override // java.lang.Iterable
        public Iterator iterator() {
            return this.f35071p.iterator();
        }
    }

    /* loaded from: classes3.dex */
    public static final class b extends v implements dn.l {

        /* renamed from: p */
        public static final b f35072p = new b();

        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a */
        public final Boolean invoke(Object obj) {
            return Boolean.valueOf(obj == null);
        }
    }

    /* loaded from: classes3.dex */
    public /* synthetic */ class c extends kotlin.jvm.internal.q implements dn.l {

        /* renamed from: p */
        public static final c f35073p = new c();

        c() {
            super(1, h.class, "iterator", "iterator()Ljava/util/Iterator;", 0);
        }

        @Override // dn.l
        /* renamed from: l */
        public final Iterator invoke(h p02) {
            t.g(p02, "p0");
            return p02.iterator();
        }
    }

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

        /* renamed from: a */
        final /* synthetic */ h f35074a;

        /* renamed from: b */
        final /* synthetic */ Comparator f35075b;

        d(h hVar, Comparator comparator) {
            this.f35074a = hVar;
            this.f35075b = comparator;
        }

        @Override // rp.h
        public Iterator iterator() {
            List F;
            F = p.F(this.f35074a);
            y.z(F, this.f35075b);
            return F.iterator();
        }
    }

    public static h A(h hVar, Object obj) {
        t.g(hVar, "<this>");
        return n.f(n.j(hVar, n.j(obj)));
    }

    public static h B(h hVar, Comparator comparator) {
        t.g(hVar, "<this>");
        t.g(comparator, "comparator");
        return new d(hVar, comparator);
    }

    public static h C(h hVar, dn.l predicate) {
        t.g(hVar, "<this>");
        t.g(predicate, "predicate");
        return new q(hVar, predicate);
    }

    public static final Collection D(h hVar, Collection destination) {
        t.g(hVar, "<this>");
        t.g(destination, "destination");
        Iterator it = hVar.iterator();
        while (it.hasNext()) {
            destination.add(it.next());
        }
        return destination;
    }

    public static List E(h hVar) {
        List e10;
        List k10;
        t.g(hVar, "<this>");
        Iterator it = hVar.iterator();
        if (!it.hasNext()) {
            k10 = u.k();
            return k10;
        }
        Object next = it.next();
        if (!it.hasNext()) {
            e10 = sm.t.e(next);
            return e10;
        }
        ArrayList arrayList = new ArrayList();
        arrayList.add(next);
        while (it.hasNext()) {
            arrayList.add(it.next());
        }
        return arrayList;
    }

    public static List F(h hVar) {
        t.g(hVar, "<this>");
        return (List) D(hVar, new ArrayList());
    }

    public static boolean k(h hVar) {
        t.g(hVar, "<this>");
        return hVar.iterator().hasNext();
    }

    public static Iterable l(h hVar) {
        t.g(hVar, "<this>");
        return new a(hVar);
    }

    public static int m(h hVar) {
        t.g(hVar, "<this>");
        Iterator it = hVar.iterator();
        int i10 = 0;
        while (it.hasNext()) {
            it.next();
            i10++;
            if (i10 < 0) {
                u.t();
            }
        }
        return i10;
    }

    public static h n(h hVar, int i10) {
        t.g(hVar, "<this>");
        if (i10 >= 0) {
            return i10 == 0 ? hVar : hVar instanceof rp.c ? ((rp.c) hVar).a(i10) : new rp.b(hVar, i10);
        }
        throw new IllegalArgumentException(("Requested element count " + i10 + " is less than zero.").toString());
    }

    public static h o(h hVar, dn.l predicate) {
        t.g(hVar, "<this>");
        t.g(predicate, "predicate");
        return new e(hVar, true, predicate);
    }

    public static h p(h hVar, dn.l predicate) {
        t.g(hVar, "<this>");
        t.g(predicate, "predicate");
        return new e(hVar, false, predicate);
    }

    public static h q(h hVar) {
        h p10;
        t.g(hVar, "<this>");
        p10 = p(hVar, b.f35072p);
        t.e(p10, "null cannot be cast to non-null type kotlin.sequences.Sequence<T of kotlin.sequences.SequencesKt___SequencesKt.filterNotNull>");
        return p10;
    }

    public static Object r(h hVar) {
        t.g(hVar, "<this>");
        Iterator it = hVar.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        return null;
    }

    public static h s(h hVar, dn.l transform) {
        t.g(hVar, "<this>");
        t.g(transform, "transform");
        return new f(hVar, transform, c.f35073p);
    }

    public static final Appendable t(h hVar, Appendable buffer, CharSequence separator, CharSequence prefix, CharSequence postfix, int i10, CharSequence truncated, dn.l lVar) {
        t.g(hVar, "<this>");
        t.g(buffer, "buffer");
        t.g(separator, "separator");
        t.g(prefix, "prefix");
        t.g(postfix, "postfix");
        t.g(truncated, "truncated");
        buffer.append(prefix);
        int i11 = 0;
        for (Object obj : hVar) {
            i11++;
            if (i11 > 1) {
                buffer.append(separator);
            }
            if (i10 >= 0 && i11 > i10) {
                break;
            }
            kotlin.text.q.a(buffer, obj, lVar);
        }
        if (i10 >= 0 && i11 > i10) {
            buffer.append(truncated);
        }
        buffer.append(postfix);
        return buffer;
    }

    public static final String u(h hVar, CharSequence separator, CharSequence prefix, CharSequence postfix, int i10, CharSequence truncated, dn.l lVar) {
        t.g(hVar, "<this>");
        t.g(separator, "separator");
        t.g(prefix, "prefix");
        t.g(postfix, "postfix");
        t.g(truncated, "truncated");
        String sb2 = ((StringBuilder) t(hVar, new StringBuilder(), separator, prefix, postfix, i10, truncated, lVar)).toString();
        t.f(sb2, "toString(...)");
        return sb2;
    }

    public static /* synthetic */ String v(h hVar, CharSequence charSequence, CharSequence charSequence2, CharSequence charSequence3, int i10, CharSequence charSequence4, dn.l lVar, int i11, Object obj) {
        if ((i11 & 1) != 0) {
            charSequence = ", ";
        }
        CharSequence charSequence5 = (i11 & 2) != 0 ? "" : charSequence2;
        CharSequence charSequence6 = (i11 & 4) == 0 ? charSequence3 : "";
        if ((i11 & 8) != 0) {
            i10 = -1;
        }
        int i12 = i10;
        if ((i11 & 16) != 0) {
            charSequence4 = "...";
        }
        CharSequence charSequence7 = charSequence4;
        if ((i11 & 32) != 0) {
            lVar = null;
        }
        return u(hVar, charSequence, charSequence5, charSequence6, i12, charSequence7, lVar);
    }

    public static Object w(h hVar) {
        t.g(hVar, "<this>");
        Iterator it = hVar.iterator();
        if (!it.hasNext()) {
            throw new NoSuchElementException("Sequence is empty.");
        }
        Object next = it.next();
        while (it.hasNext()) {
            next = it.next();
        }
        return next;
    }

    public static h x(h hVar, dn.l transform) {
        t.g(hVar, "<this>");
        t.g(transform, "transform");
        return new r(hVar, transform);
    }

    public static h y(h hVar, dn.l transform) {
        h q10;
        t.g(hVar, "<this>");
        t.g(transform, "transform");
        q10 = q(new r(hVar, transform));
        return q10;
    }

    public static h z(h hVar, Iterable elements) {
        h S;
        t.g(hVar, "<this>");
        t.g(elements, "elements");
        S = c0.S(elements);
        return n.f(n.j(hVar, S));
    }
}
