content: package kotlin.collections;
  
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.Map;
  import kotlin.Metadata;
  import kotlin.jvm.functions.Function2;
  import kotlin.jvm.functions.Function3;
  import kotlin.jvm.functions.Function4;
  import kotlin.jvm.internal.Intrinsics;
  
  @Metadata(d1 = {"\u0000@\n\u0000\n\u0002\u0010$\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010%\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\n\u001a\u0001\u0010\u0000\u001a\u000e\u0012\u0004\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0001\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052b\u0010\u0006\u001a^\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0015\u0012\u0013\u0018\u0001H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0013\u0012\u00110\r¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000e\u0012\u0004\u0012\u0002H\u00030\u0007H\bø\u0001\u0000\u001a·\u0001\u0010\u000f\u001a\u0002H\u0010\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003\"\u0016\b\u0003\u0010\u0010*\u0010\u0012\u0006\b\u0000\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0011*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u0012\u001a\u0002H\u00102b\u0010\u0006\u001a^\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0015\u0012\u0013\u0018\u0001H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0013\u0012\u00110\r¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000e\u0012\u0004\u0012\u0002H\u00030\u0007H\bø\u0001\u0000¢\u0006\u0002\u0010\u0013\u001aI\u0010\u0014\u001a\u0002H\u0010\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0016\b\u0002\u0010\u0010*\u0010\u0012\u0006\b\u0000\u0012\u0002H\u0002\u0012\u0004\u0012\u00020\u00150\u0011*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u0012\u001a\u0002H\u0010H\u0007¢\u0006\u0002\u0010\u0016\u001a¿\u0001\u0010\u0017\u001a\u000e\u0012\u0004\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0001\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u000526\u0010\u0018\u001a2\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u00192K\u0010\u0006\u001aG\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u001aH\bø\u0001\u0000\u001a\u0010\u0017\u001a\u000e\u0012\u0004\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0001\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u001b\u001a\u0002H\u000326\u0010\u0006\u001a2\u0012\u0013\u0012\u0011H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u0019H\bø\u0001\u0000¢\u0006\u0002\u0010\u001c\u001aØ\u0001\u0010\u001d\u001a\u0002H\u0010\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003\"\u0016\b\u0003\u0010\u0010*\u0010\u0012\u0006\b\u0000\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0011*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u0012\u001a\u0002H\u001026\u0010\u0018\u001a2\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u00192K\u0010\u0006\u001aG\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u001aH\bø\u0001\u0000¢\u0006\u0002\u0010\u001e\u001a\u0001\u0010\u001d\u001a\u0002H\u0010\"\u0004\b\u0000\u0010\u0004\"\u0004\b\u0001\u0010\u0002\"\u0004\b\u0002\u0010\u0003\"\u0016\b\u0003\u0010\u0010*\u0010\u0012\u0006\b\u0000\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H\u00030\u0011*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u0012\u001a\u0002H\u00102\u0006\u0010\u001b\u001a\u0002H\u000326\u0010\u0006\u001a2\u0012\u0013\u0012\u0011H\u0003¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H\u00030\u0019H\bø\u0001\u0000¢\u0006\u0002\u0010\u001f\u001a\u0001\u0010 \u001a\u000e\u0012\u0004\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H!0\u0001\"\u0004\b\u0000\u0010!\"\b\b\u0001\u0010\u0004*\u0002H!\"\u0004\b\u0002\u0010\u0002*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052K\u0010\u0006\u001aG\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H!¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H!0\u001aH\bø\u0001\u0000\u001a¤\u0001\u0010\"\u001a\u0002H\u0010\"\u0004\b\u0000\u0010!\"\b\b\u0001\u0010\u0004*\u0002H!\"\u0004\b\u0002\u0010\u0002\"\u0016\b\u0003\u0010\u0010*\u0010\u0012\u0006\b\u0000\u0012\u0002H\u0002\u0012\u0004\u0012\u0002H!0\u0011*\u000e\u0012\u0004\u0012\u0002H\u0004\u0012\u0004\u0012\u0002H\u00020\u00052\u0006\u0010\u0012\u001a\u0002H\u00102K\u0010\u0006\u001aG\u0012\u0013\u0012\u0011H\u0002¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\n\u0012\u0013\u0012\u0011H!¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\u000b\u0012\u0013\u0012\u0011H\u0004¢\u0006\f\b\b\u0012\b\b\t\u0012\u0004\b\b(\f\u0012\u0004\u0012\u0002H!0\u001aH\bø\u0001\u0000¢\u0006\u0002\u0010#\u0002\u0007\n\u0005\b20\u0001¨\u0006$"}, d2 = {"aggregate", "", "K", "R", "T", "Lkotlin/collections/Grouping;", "operation", "Lkotlin/Function4;", "Lkotlin/ParameterName;", "name", "key", "accumulator", "element", "", "first", "aggregateTo", "M", "", "destination", "(Lkotlin/collections/Grouping;Ljava/util/Map;Lkotlin/jvm/functions/Function4;)Ljava/util/Map;", "eachCountTo", "", "(Lkotlin/collections/Grouping;Ljava/util/Map;)Ljava/util/Map;", "fold", "initialValueSelector", "Lkotlin/Function2;", "Lkotlin/Function3;", "initialValue", "(Lkotlin/collections/Grouping;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/util/Map;", "foldTo", "(Lkotlin/collections/Grouping;Ljava/util/Map;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)Ljava/util/Map;", "(Lkotlin/collections/Grouping;Ljava/util/Map;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/util/Map;", "reduce", "S", "reduceTo", "(Lkotlin/collections/Grouping;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)Ljava/util/Map;", "kotlin-stdlib"}, k = 5, mv = {1, 7, 1}, xi = 49, xs = "kotlin/collections/GroupingKt")
  /* compiled from: Grouping.kt */
  class GroupingKt__GroupingKt extends GroupingKt__GroupingJVMKt {
      public static final <T, K, R> Map<K, R> aggregate(Grouping<T, ? extends K> $this$aggregate, Function4<? super K, ? super R, ? super T, ? super Boolean, ? extends R> operation) {
          Intrinsics.checkNotNullParameter($this$aggregate, "<this>");
          Intrinsics.checkNotNullParameter(operation, "operation");
          Map<K, R> linkedHashMap = new LinkedHashMap<>();
          Grouping<T, ? extends K> grouping = $this$aggregate;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              R r = linkedHashMap.get(keyOf);
              linkedHashMap.put(keyOf, operation.invoke(keyOf, r, next, Boolean.valueOf(r == null && !linkedHashMap.containsKey(keyOf))));
          }
          return linkedHashMap;
      }
  
      public static final <T, K, R, M extends Map<? super K, R>> M aggregateTo(Grouping<T, ? extends K> $this$aggregateTo, M destination, Function4<? super K, ? super R, ? super T, ? super Boolean, ? extends R> operation) {
          Intrinsics.checkNotNullParameter($this$aggregateTo, "<this>");
          Intrinsics.checkNotNullParameter(destination, "destination");
          Intrinsics.checkNotNullParameter(operation, "operation");
          Iterator<T> sourceIterator = $this$aggregateTo.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = $this$aggregateTo.keyOf(next);
              Object obj = destination.get(keyOf);
              destination.put(keyOf, operation.invoke(keyOf, obj, next, Boolean.valueOf(obj == null && !destination.containsKey(keyOf))));
          }
          return destination;
      }
  
      public static final <T, K, M extends Map<? super K, Integer>> M eachCountTo(Grouping<T, ? extends K> $this$eachCountTo, M destination) {
          M m = destination;
          Intrinsics.checkNotNullParameter($this$eachCountTo, "<this>");
          Intrinsics.checkNotNullParameter(m, "destination");
          Grouping<T, ? extends K> grouping = $this$eachCountTo;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              Object obj = m.get(keyOf);
              T t = next;
              m.put(keyOf, Integer.valueOf(((Number) (obj == null && !m.containsKey(keyOf) ? 0 : obj)).intValue() + 1));
          }
          return m;
      }
  
      public static final <T, K, R> Map<K, R> fold(Grouping<T, ? extends K> $this$fold, R initialValue, Function2<? super R, ? super T, ? extends R> operation) {
          Function2<? super R, ? super T, ? extends R> function2 = operation;
          Intrinsics.checkNotNullParameter($this$fold, "<this>");
          Intrinsics.checkNotNullParameter(function2, "operation");
          boolean z = false;
          Map<K, R> linkedHashMap = new LinkedHashMap<>();
          Grouping<T, ? extends K> grouping = $this$fold;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              R r = linkedHashMap.get(keyOf);
              boolean z2 = z;
              linkedHashMap.put(keyOf, function2.invoke(r == null && !linkedHashMap.containsKey(keyOf) ? initialValue : r, next));
              z = z2;
          }
          return linkedHashMap;
      }
  
      public static final <T, K, R> Map<K, R> fold(Grouping<T, ? extends K> $this$fold, Function2<? super K, ? super T, ? extends R> initialValueSelector, Function3<? super K, ? super R, ? super T, ? extends R> operation) {
          boolean z;
          Object obj;
          R r;
          Function2<? super K, ? super T, ? extends R> function2 = initialValueSelector;
          Function3<? super K, ? super R, ? super T, ? extends R> function3 = operation;
          Intrinsics.checkNotNullParameter($this$fold, "<this>");
          Intrinsics.checkNotNullParameter(function2, "initialValueSelector");
          Intrinsics.checkNotNullParameter(function3, "operation");
          boolean z2 = false;
          Map<K, R> linkedHashMap = new LinkedHashMap<>();
          Grouping<T, ? extends K> grouping = $this$fold;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              R r2 = linkedHashMap.get(keyOf);
              R r3 = r2;
              T t = next;
              Object obj2 = keyOf;
              if (r2 == null && !linkedHashMap.containsKey(keyOf)) {
                  z = z2;
                  obj = obj2;
                  r = function2.invoke(obj, t);
              } else {
                  z = z2;
                  obj = obj2;
                  r = r3;
              }
              linkedHashMap.put(keyOf, function3.invoke(obj, r, t));
              function2 = initialValueSelector;
              z2 = z;
          }
          return linkedHashMap;
      }
  
      public static final <T, K, R, M extends Map<? super K, R>> M foldTo(Grouping<T, ? extends K> $this$foldTo, M destination, R initialValue, Function2<? super R, ? super T, ? extends R> operation) {
          Intrinsics.checkNotNullParameter($this$foldTo, "<this>");
          Intrinsics.checkNotNullParameter(destination, "destination");
          Intrinsics.checkNotNullParameter(operation, "operation");
          Grouping<T, ? extends K> grouping = $this$foldTo;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              R r = destination.get(keyOf);
              destination.put(keyOf, operation.invoke(r == null && !destination.containsKey(keyOf) ? initialValue : r, next));
          }
          return destination;
      }
  
      public static final <T, K, R, M extends Map<? super K, R>> M foldTo(Grouping<T, ? extends K> $this$foldTo, M destination, Function2<? super K, ? super T, ? extends R> initialValueSelector, Function3<? super K, ? super R, ? super T, ? extends R> operation) {
          M m = destination;
          Function2<? super K, ? super T, ? extends R> function2 = initialValueSelector;
          Function3<? super K, ? super R, ? super T, ? extends R> function3 = operation;
          Intrinsics.checkNotNullParameter($this$foldTo, "<this>");
          Intrinsics.checkNotNullParameter(m, "destination");
          Intrinsics.checkNotNullParameter(function2, "initialValueSelector");
          Intrinsics.checkNotNullParameter(function3, "operation");
          Grouping<T, ? extends K> grouping = $this$foldTo;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              Object obj = m.get(keyOf);
              Object obj2 = keyOf;
              T t = next;
              m.put(keyOf, function3.invoke(obj2, obj == null && !m.containsKey(keyOf) ? function2.invoke(obj2, t) : obj, t));
              function2 = initialValueSelector;
          }
          return m;
      }
  
      public static final <S, T extends S, K> Map<K, S> reduce(Grouping<T, ? extends K> $this$reduce, Function3<? super K, ? super S, ? super T, ? extends S> operation) {
          Function3<? super K, ? super S, ? super T, ? extends S> function3 = operation;
          Intrinsics.checkNotNullParameter($this$reduce, "<this>");
          Intrinsics.checkNotNullParameter(function3, "operation");
          Map<K, S> linkedHashMap = new LinkedHashMap<>();
          Grouping<T, ? extends K> grouping = $this$reduce;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              T next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              S s = linkedHashMap.get(keyOf);
              Object obj = keyOf;
              S s2 = s;
              T t = next;
              if (!(s == null && !linkedHashMap.containsKey(keyOf))) {
                  t = function3.invoke(obj, s2, t);
              }
              linkedHashMap.put(keyOf, t);
          }
          return linkedHashMap;
      }
  
      public static final <S, T extends S, K, M extends Map<? super K, S>> M reduceTo(Grouping<T, ? extends K> $this$reduceTo, M destination, Function3<? super K, ? super S, ? super T, ? extends S> operation) {
          Intrinsics.checkNotNullParameter($this$reduceTo, "<this>");
          Intrinsics.checkNotNullParameter(destination, "destination");
          Intrinsics.checkNotNullParameter(operation, "operation");
          Grouping<T, ? extends K> grouping = $this$reduceTo;
          Iterator<T> sourceIterator = grouping.sourceIterator();
          while (sourceIterator.hasNext()) {
              Object next = sourceIterator.next();
              Object keyOf = grouping.keyOf(next);
              Object obj = destination.get(keyOf);
              Object obj2 = obj;
              Object obj3 = keyOf;
              Object obj4 = next;
              if (!(obj == null && !destination.containsKey(keyOf))) {
                  obj4 = operation.invoke(obj3, obj2, obj4);
              }
              destination.put(keyOf, obj4);
          }
          return destination;
      }
  }
  