Package ste.lloop
Class Loop
java.lang.Object
ste.lloop.Loop
Provides a fluent API for creating loops.
This class is the main entry point for creating loops. Use one of the static on methods
to start building a loop.
Example usage:
// Numeric loop from 0 to 10 (inclusive)
Loop.on().from(0).to(10).loop(i -> {
// do something with i
});
// Loop over an array of strings
Loop.on("a", "b", "c").loop(element -> {
// do something with element
});
// Loop over an array of strings, from index 1 up to (and including) index 3
Loop.on(new String[]{"a", "b", "c", "d"}).from(1).to(3).loop((index, element) -> {
// do something with index and element
});
// Numeric loop from 0 to 10, with a step of 2
Loop.on().from(0).to(10).step(2).loop(i -> {
// i will be 0, 2, 4, 6, 8, 10
});
// Numeric loop from 0 to 10, with a negative step of -2 (inverts direction)
Loop.on().from(0).to(10).step(-2).loop(i -> {
// i will be 10, 8, 6, 4, 2, 0
});
-
Method Summary
Modifier and TypeMethodDescriptionstatic NumericSerieson()Creates a new numeric loop.static <T> Sequence<T> on(T... items) Creates a new loop over the given items.
-
Method Details
-
on
Creates a new numeric loop.- Returns:
- a new
NumericSeriesinstance
-
on
Creates a new loop over the given items. This method supports both varargs and passing an array directly.- Type Parameters:
T- the type of the items- Parameters:
items- the items to loop over (can be varargs or an array)- Returns:
- a new
Sequenceinstance
-