All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.scravy.bedrock.ExtendedIterable Maven / Gradle / Ivy

package de.scravy.bedrock;

@FunctionalInterface
public interface ExtendedIterable extends Iterable, HasLengthAtLeast {

  @FunctionalInterface
  interface ForEachWithIndexConsumer {
    void accept(final int index, final T thing);
  }

  default void forEachWithIndex(final ForEachWithIndexConsumer consumer) {
    int i = 0;
    for (final T t : this) {
      try {
        consumer.accept(i, t);
      } finally {
        i += 1;
      }
    }
  }

  @Override
  default boolean lengthAtLeast(final int length) {
    int count = 0;
    for (final T ignore : this) {
      count += 1;
      if (count >= length) {
        return true;
      }
    }
    return false;
  }

  static  ExtendedIterable fromIterable(final Iterable iterable) {
    return iterable::iterator;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy