repeat(n, i -> ...)
Kotlin-style repetition for Java, with support for checked exceptions.
import static io.github.repeat.Repeat.*;
// run an action n times
repeat(3, i -> System.out.println("attempt " + i));
// checked exceptions propagate without wrapping
repeat(3, i -> Files.createFile(Paths.get("file-" + i)));
// throws IOExceptionInstall
One dependency, no transitive dependencies. Java 8 or later.
<dependency>
<groupId>io.github.java-repeat</groupId>
<artifactId>repeat</artifactId>
<version>1.0.1</version>
</dependency>implementation("io.github.java-repeat:repeat:1.0.1")If you know Kotlin
Same name, same index, same rules. As in Kotlin, a zero or negative count does nothing.
| KOTLIN | JAVA-REPEAT |
|---|---|
| repeat(n) { i -> ... } | repeat(n, i -> ...) |
| repeat(0) { ... } | repeat(0, i -> ...) // no-op |
Documentation
START
Getting started
Add the dependency and make your first call.
API
API reference
Repeat and IndexedAction: signatures, behavior, examples.
API
Javadoc ↗
Generated Javadoc for every version on javadoc.io.
GUIDE
Checked exceptions
How E is inferred and what happens when an iteration throws.
GUIDE
Migrating from 0.x
Replace Repeat.of().times(n).repeat(...) with repeat(n, ...).
PROJECT
Releases ↗
Versions and release notes on GitHub.