![JAR search and dependency download from the Maven repository](/logo.png)
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