static <A, B> F<A, B> fix(F<F<A, B>, F<A, B>> f, F<F0<B>, B> delay) { return new F<A, B>() { final F<A, B> rec = f.f(this); @Override public B f(A a) { return delay.f(() -> rec.f(a)); } }; }
@Override public <X> X either(F<A, X> left, F<B, X> right) { return left.f(a); } }
@Override public <B> B match( final F<One<V, A>, B> one, final F<Two<V, A>, B> two, final F<Three<V, A>, B> three, final F<Four<V, A>, B> four) { return one.f(this); }
/** * Function composition. * * @param f A function to compose with another. * @param g A function to compose with another. * @return A function that is the composition of the given arguments. */ public static <A, B, C, D> F<A, F<B, D>> compose2(final F<C, D> f, final F<A, F<B, C>> g) { return a -> b -> f.f(g.f(a).f(b)); }
@Override public <B> B match( final F<One<V, A>, B> one, final F<Two<V, A>, B> two, final F<Three<V, A>, B> three, final F<Four<V, A>, B> four) { return three.f(this); }
/** * Returns the potential successor of a value for this enumerator. * * @param a The value to return the successor of. * @return The potential successor of a value for this enumerator. */ public Option<A> successor(final A a) { return successor.f(a); }
/** * Pattern matching on the structure of this tree. Matches the singleton tree. */ @Override public <B> B match(final F<Empty<V, A>, B> empty, final F<Single<V, A>, B> single, final F<Deep<V, A>, B> deep) { return single.f(this); }
/** * Binds a given function across this function (Reader Monad). * * @param g A function that takes the return value of this function as an argument, yielding a new function. * @return A function that invokes this function on its argument and then the given function on the result. */ public static <A, B, C> F<A, C> bind(final F<A, B> f, final F<B, F<A, C>> g) { return a -> g.f(f.f(a)).f(a); }
/** * Curry a function of arity-8. * * @param f The function to curry. * @param a An argument to the curried function. * @param b An argument to the curried function. * @return A curried form of the given function. */ public static <A, B, C, D, E, F$, G, H, I> F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>> curry( final F8<A, B, C, D, E, F$, G, H, I> f, final A a, final B b) { return curry(f).f(a).f(b); }
/** * OOP style 'withers': */ public final Request withPath(String newPath) { return Requests.setPath(newPath).f(this); }
public final Request withBody(String newBody) { // if there is no body field (eg. GET, DELETE) then the original request is // returned (no modification): return Requests.setBody(newBody).f(this); }
@Override public C _3() { return fc.f(unit()); } @Override
@Override public B _2() { return fb.f(unit()); } @Override