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

me.shaftesbury.utils.functional.UnaryFunction Maven / Gradle / Ivy

There is a newer version: 1.17
Show newest version
package me.shaftesbury.utils.functional;

/**
 * Created with IntelliJ IDEA.
 * User: Bob
 * Date: 01/12/13
 * Time: 23:36
 * To change this template use File | Settings | File Templates.
 */
public abstract class UnaryFunction implements Func
{
    public UnaryFunction then(final Func f)
    {
        return compose(this,f);
    }

    private static final UnaryFunction compose(final Func f, final Func g)
    {
        return new UnaryFunction()
        {
            public C apply(final A a) { return g.apply(f.apply(a));}
        };
    }

    public static final Func0 delay(final Func f, final A a)
    {
        return new Func0()
        {
            @Override
            public B apply() {
                return f.apply(a);
            }
        };
    }
}