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

import java.util.function.Function;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public interface CoFunction<T,R> {

    T invert(R value);
    
    static <T> CoFunction<T,T> identity() {
        return v -> v;
    }
    
    static <T,R> CoFunction<T,R> inverted(Function<R,T> f) {
        return v -> f.apply(v);
    }
    
    static <T,R> Function<R,T> inverted(CoFunction<T,R> f) {
        return v -> f.invert(v);
    }
    
}
