code: @Override
    public int removeAll(KTypePredicate<? super KType> predicate) {
      final KType[] buffer = Intrinsics.<KType[]> cast(this.buffer);
      final int elementsCount = this.elementsCount;
      int to = 0;
      int from = 0;
      try {
        for (; from < elementsCount; from++) {
          if (predicate.apply(buffer[from])) {
            buffer[from] = Intrinsics.empty();
            continue;
          }
  
          if (to != from) {
            buffer[to] = buffer[from];
            buffer[from] = Intrinsics.empty();
          }
          to++;
        }
      } finally {
        // Keep the list in a consistent state, even if the predicate throws an exception.
        for (; from < elementsCount; from++) {
          if (to != from) {
            buffer[to] = buffer[from];
            buffer[from] = Intrinsics.empty();
          }
          to++;
        }
  
        this.elementsCount = to;
      }
  
      return elementsCount - to;
    }
docs: {@inheritDoc}