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

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 run(RandomState input) {
        Result r1 = a.run(input);
        Result r2 = b.run(r1.getNextState());
        Result r3 = c.run(r2.getNextState());
        Result r4 = d.run(r3.getNextState());
        Result 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);
    }

}