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

dev.marksman.composablerandom.choice.ChoiceBuilder6 Maven / Gradle / Ivy

package dev.marksman.composablerandom.choice;

import com.jnape.palatable.lambda.adt.choice.Choice6;
import com.jnape.palatable.lambda.adt.choice.Choice7;
import dev.marksman.composablerandom.FrequencyEntry;
import dev.marksman.composablerandom.Generator;
import dev.marksman.composablerandom.ToGenerator;
import dev.marksman.composablerandom.frequency.FrequencyMap;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;

import static dev.marksman.composablerandom.Generator.constant;
import static dev.marksman.composablerandom.choice.ChoiceBuilder7.choiceBuilder7;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ChoiceBuilder6 implements ToGenerator> {
    private final FrequencyMap> frequencyMap;

    @Override
    public Generator> toGenerator() {
        return frequencyMap.toGenerator();
    }

    public  ChoiceBuilder7 or(int weight, Generator generator) {
        FrequencyMap> newFrequencyMap = frequencyMap
                .>fmap(c6 ->
                        c6.match(Choice7::a, Choice7::b, Choice7::c, Choice7::d, Choice7::e, Choice7::f))
                .add(weight, generator.fmap(Choice7::g));
        return choiceBuilder7(newFrequencyMap);
    }

    public  ChoiceBuilder7 or(Generator generator) {
        return or(1, generator);
    }

    public  ChoiceBuilder7 or(FrequencyEntry frequencyEntry) {
        return or(frequencyEntry.getWeight(), frequencyEntry.getGenerator());
    }

    public  ChoiceBuilder7 orValue(int weight, G value) {
        return or(weight, constant(value));
    }

    public  ChoiceBuilder7 orValue(G value) {
        return or(1, constant(value));
    }

    public static  ChoiceBuilder6 choiceBuilder6(FrequencyMap> frequencyMap) {
        return new ChoiceBuilder6<>(frequencyMap);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy