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

com.jnape.palatable.lambda.functions.builtin.fn5.LiftA4 Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package com.jnape.palatable.lambda.functions.builtin.fn5;

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.functor.Applicative;

/**
 * Lift into and apply an {@link Fn4} to four {@link Applicative} values, returning the result inside the same
 * {@link Applicative} context.
 *
 * @param     the function's first argument type
 * @param     the function's second argument type
 * @param     the function's third argument type
 * @param     the function's fourth argument type
 * @param     the function's return type
 * @param   the applicative witness
 * @param  the inferred applicative return type
 * @see Applicative#zip(Applicative)
 */
public final class LiftA4, AppE extends Applicative> implements
        Fn5, Applicative, Applicative, Applicative, Applicative,
                AppE> {

    private static final LiftA4 INSTANCE = new LiftA4<>();

    private LiftA4() {
    }

    @Override
    public AppE checkedApply(Fn4 fn, Applicative appA, Applicative appB,
                             Applicative appC, Applicative appD) {
        return appA.zip(appB.zip(appC.zip(appD.fmap(d -> c -> b -> a -> fn.apply(a, b, c, d))))).coerce();
    }

    @SuppressWarnings("unchecked")
    public static , AppE extends Applicative>
    LiftA4 liftA4() {
        return (LiftA4) INSTANCE;
    }

    public static , AppE extends Applicative>
    Fn4, Applicative, Applicative, Applicative, AppE> liftA4(
            Fn4 fn) {
        return LiftA4.liftA4().apply(fn);
    }

    public static , AppE extends Applicative>
    Fn3, Applicative, Applicative, AppE> liftA4(Fn4 fn,
                                                                                    Applicative appA) {
        return LiftA4.liftA4(fn).apply(appA);
    }

    public static , AppE extends Applicative>
    Fn2, Applicative, AppE> liftA4(Fn4 fn,
                                                               Applicative appA,
                                                               Applicative appB) {
        return LiftA4.liftA4(fn, appA).apply(appB);
    }

    public static , AppE extends Applicative>
    Fn1, AppE> liftA4(Fn4 fn,
                                          Applicative appA,
                                          Applicative appB,
                                          Applicative appC) {
        return LiftA4.liftA4(fn, appA, appB).apply(appC);
    }

    public static , AppE extends Applicative>
    AppE liftA4(Fn4 fn,
                Applicative appA,
                Applicative appB,
                Applicative appC,
                Applicative appD) {
        return LiftA4.liftA4(fn, appA, appB, appC).apply(appD);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy