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

com.jnape.palatable.lambda.functions.builtin.fn2.Into1 Maven / Gradle / Ivy

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

import com.jnape.palatable.lambda.adt.hlist.SingletonHList;
import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;

import java.util.function.Function;

/**
 * Given a {@link Function}<A, B> and a {@link SingletonHList}<A>,
 * pop the head and apply it to the function, returning the result.
 *
 * @param  the first argument type
 * @param  the result type
 */
public final class Into1 implements Fn2, SingletonHList, B> {

    private static final Into1 INSTANCE = new Into1();

    @Override
    public B apply(Function fn, SingletonHList singletonHList) {
        return fn.apply(singletonHList.head());
    }

    @SuppressWarnings("unchecked")
    public static  Into1 into1() {
        return INSTANCE;
    }

    public static  Fn1, B> into1(Function fn) {
        return Into1.into1().apply(fn);
    }

    public static  B into1(Function fn, SingletonHList singletonHList) {
        return Into1.into1(fn).apply(singletonHList);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy