dev.marksman.composablerandom.primitives.Product5Impl Maven / Gradle / Ivy
package dev.marksman.composablerandom.primitives;
import com.jnape.palatable.lambda.functions.Fn5;
import dev.marksman.composablerandom.CompiledGenerator;
import dev.marksman.composablerandom.RandomState;
import dev.marksman.composablerandom.Result;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import static dev.marksman.composablerandom.Result.result;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Product5Impl implements CompiledGenerator {
private final CompiledGenerator a;
private final CompiledGenerator b;
private final CompiledGenerator c;
private final CompiledGenerator d;
private final CompiledGenerator e;
private final Fn5 combine;
@Override
public Result extends RandomState, Out> run(RandomState input) {
Result extends RandomState, A> r1 = a.run(input);
Result extends RandomState, B> r2 = b.run(r1.getNextState());
Result extends RandomState, C> r3 = c.run(r2.getNextState());
Result extends RandomState, D> r4 = d.run(r3.getNextState());
Result extends RandomState, E> r5 = e.run(r4.getNextState());
Out result = combine.apply(r1.getValue(), r2.getValue(), r3.getValue(), r4.getValue(),
r5.getValue());
return result(r5.getNextState(), result);
}
public static Product5Impl product5Impl(CompiledGenerator a,
CompiledGenerator b,
CompiledGenerator c,
CompiledGenerator d,
CompiledGenerator e,
Fn5 combine) {
return new Product5Impl<>(a, b, c, d, e, combine);
}
}