All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnape.palatable.lambda.functions.builtin.fn2.Replicate Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
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