/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.functional;

import java.io.Serializable;
import java.util.function.IntFunction;
import java.util.function.IntUnaryOperator;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public interface IntProjectionFunction extends IntFunction<Integer>, IntUnaryOperator, IntCoFunction {

    static IntProjectionFunction identity() {
        return produce(v->v, v->v);
    }

    @Override
    default Integer apply(int value) {
        return applyAsInt(value);
    }
    
    static IntProjectionFunction produce(IntUnaryOperator f, IntCoFunction cf) {
        class IPF implements IntProjectionFunction, Serializable {
			
			private static final long serialVersionUID = 1L;
			
            @Override
            public int applyAsInt(int operand) {
                return f.applyAsInt(operand);
            }

            @Override
            public int invert(int value) {
                return cf.invert(value);
            }
        };
		return new IPF();
    }
    
}
