com.jnape.palatable.lambda.functions.builtin.fn2.Into1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
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 super A, ? extends B> fn, SingletonHList singletonHList) {
return fn.apply(singletonHList.head());
}
@SuppressWarnings("unchecked")
public static Into1 into1() {
return INSTANCE;
}
public static Fn1, B> into1(Function super A, ? extends B> fn) {
return Into1.into1().apply(fn);
}
public static B into1(Function super A, ? extends B> fn, SingletonHList singletonHList) {
return Into1.into1(fn).apply(singletonHList);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy