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

dev.marksman.kraftwerk.Functions Maven / Gradle / Ivy

The newest version!
package dev.marksman.kraftwerk;

import com.jnape.palatable.lambda.adt.product.Product2;
import com.jnape.palatable.lambda.adt.product.Product3;
import com.jnape.palatable.lambda.adt.product.Product4;
import com.jnape.palatable.lambda.adt.product.Product5;
import com.jnape.palatable.lambda.adt.product.Product6;
import com.jnape.palatable.lambda.adt.product.Product7;
import com.jnape.palatable.lambda.adt.product.Product8;
import com.jnape.palatable.lambda.functions.Fn0;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
import com.jnape.palatable.lambda.functions.Fn3;
import com.jnape.palatable.lambda.functions.Fn4;
import com.jnape.palatable.lambda.functions.Fn5;
import com.jnape.palatable.lambda.functions.Fn6;
import com.jnape.palatable.lambda.functions.Fn7;
import com.jnape.palatable.lambda.functions.Fn8;

import static dev.marksman.kraftwerk.Tap.tap;

final class Functions {
    private Functions() {
    }

    static  Generator> generateFn0(Generator result) {
        return result.fmap(r -> () -> r);
    }

    static  Generator> generateFn1(Cogenerator param1,
                                                   Generator result) {
        return tap(result, (output, rs) -> a -> output.apply(param1.apply(rs, a)).getValue());
    }

    static  Generator> generateFn2(Cogenerator param1,
                                                         Cogenerator param2,
                                                         Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2);
        return Tap.tap(result,
                (output, rs) -> (a, b) -> output.apply(params.apply(rs, Product2.product(a, b))).getValue());
    }

    static  Generator> generateFn3(Cogenerator param1,
                                                               Cogenerator param2,
                                                               Cogenerator param3,
                                                               Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3);
        return Tap.tap(result,
                (output, rs) -> (a, b, c) -> output.apply(params.apply(rs, Product3.product(a, b, c))).getValue());
    }

    static  Generator> generateFn4(Cogenerator param1,
                                                                     Cogenerator param2,
                                                                     Cogenerator param3,
                                                                     Cogenerator param4,
                                                                     Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3, param4);
        return Tap.tap(result,
                (output, rs) -> (a, b, c, d) -> output.apply(params.apply(rs, Product4.product(a, b, c, d))).getValue());
    }

    static  Generator> generateFn5(Cogenerator param1,
                                                                           Cogenerator param2,
                                                                           Cogenerator param3,
                                                                           Cogenerator param4,
                                                                           Cogenerator param5,
                                                                           Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3, param4, param5);
        return Tap.tap(result,
                (output, rs) -> (a, b, c, d, e) -> output.apply(params.apply(rs, Product5.product(a, b, c, d, e))).getValue());
    }

    static  Generator> generateFn6(Cogenerator param1,
                                                                                 Cogenerator param2,
                                                                                 Cogenerator param3,
                                                                                 Cogenerator param4,
                                                                                 Cogenerator param5,
                                                                                 Cogenerator param6,
                                                                                 Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3, param4, param5, param6);
        return Tap.tap(result,
                (output, rs) -> (a, b, c, d, e, f) ->
                        output.apply(params.apply(rs, Product6.product(a, b, c, d, e, f))).getValue());
    }

    static  Generator> generateFn7(Cogenerator param1,
                                                                                       Cogenerator param2,
                                                                                       Cogenerator param3,
                                                                                       Cogenerator param4,
                                                                                       Cogenerator param5,
                                                                                       Cogenerator param6,
                                                                                       Cogenerator param7,
                                                                                       Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3, param4, param5,
                param6, param7);
        return Tap.tap(result,
                (output, rs) -> (a, b, c, d, e, f, g) ->
                        output.apply(params.apply(rs, Product7.product(a, b, c, d, e, f, g))).getValue());
    }

    static  Generator> generateFn8(Cogenerator param1,
                                                                                             Cogenerator param2,
                                                                                             Cogenerator param3,
                                                                                             Cogenerator param4,
                                                                                             Cogenerator param5,
                                                                                             Cogenerator param6,
                                                                                             Cogenerator param7,
                                                                                             Cogenerator param8,
                                                                                             Generator result) {
        Cogenerator> params = Cogenerator.product(param1, param2, param3, param4, param5,
                param6, param7, param8);
        return Tap.tap(result,
                (output, rs) -> (a, b, c, d, e, f, g, h) ->
                        output.apply(params.apply(rs, Product8.product(a, b, c, d, e, f, g, h))).getValue());
    }
}