com.jnape.palatable.lambda.functions.builtin.fn2.Replicate 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.fn2;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
import static com.jnape.palatable.lambda.functions.builtin.fn1.Repeat.repeat;
import static com.jnape.palatable.lambda.functions.builtin.fn2.Take.take;
/**
* Produce an {@link Iterable} of a value n
times.
*
* @param the output Iterable element type
*/
public final class Replicate implements Fn2> {
private static final Replicate> INSTANCE = new Replicate<>();
private Replicate() {
}
@Override
public Iterable checkedApply(Integer n, A a) {
return take(n, repeat(a));
}
@SuppressWarnings("unchecked")
public static Replicate replicate() {
return (Replicate) INSTANCE;
}
public static Fn1> replicate(Integer n) {
return Replicate.replicate().apply(n);
}
public static Iterable replicate(Integer n, A a) {
return Replicate.replicate(n).apply(a);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy