com.jnape.palatable.lambda.functions.builtin.fn1.Cycle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
package com.jnape.palatable.lambda.functions.builtin.fn1;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.iterators.CyclicIterator;
import static java.util.Arrays.asList;
/**
* Given an Iterable
, return an infinite Iterable
that repeatedly cycles its elements, in
* order.
*
* @param The Iterable element type
*/
public final class Cycle implements Fn1, Iterable> {
private static final Cycle INSTANCE = new Cycle();
private Cycle() {
}
@Override
public Iterable apply(Iterable as) {
return () -> new CyclicIterator<>(as.iterator());
}
@SuppressWarnings("unchecked")
public static Cycle cycle() {
return INSTANCE;
}
public static Iterable cycle(Iterable as) {
return Cycle.cycle().apply(as);
}
@SafeVarargs
public static Iterable cycle(A... as) {
return cycle(asList(as));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy