@Override public final C f(A a, B b) { return func.f(a, b); } }
public static <A,B> B fold(final F2<B,A,B> f, final B initial, final Iterable<A> it) { B b = initial; for (A a : it) { b = f.f(b,a); } return b; }
/** * Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function. * * @return a wrapped function of arity-1 that returns another wrapped function. */ public static <A, B, C> F<A, F<B, C>> curry(final F2<A, B, C> f) { return a -> b -> f.f(a, b); }
/** * Function argument flipping. * * @param f The function to flip. * @return The given function flipped. */ public static <A, B, C> F2<B, A, C> flip(final F2<A, B, C> f) { return (b, a) -> f.f(a, b); }
/** * Partial application. * * @param a The <code>A</code> to which to apply this function. * @return The function partially applied to the given argument. */ public static <A, B, C> F<B, C> f(final F2<A, B, C> f, final A a) { return b -> f.f(a, b); }
/** * Curry a function of arity-2. * * @param f The function to curry. * @return A curried form of the given function. */ public static <A, B, C> F<A, F<B, C>> curry(final F2<A, B, C> f) { return a -> b -> f.f(a, b); }
/** * Flips the arguments of this function. * * @return A new function with the arguments of this function flipped. */ public static <A, B, C> F2<B, A, C> flip(final F2<A, B, C> f) { return (b, a) -> f.f(a, b); }
/** * Append a given heterogeneous list to another. * * @param a a heterogeneous list to be appended to. * @param b a heterogeneous list to append to another. * @return a new heterogeneous list consisting of the second argument appended to the first. */ public C append(final A a, final B b) { return append.f(a, b); }
public C f( B b, A a ) { return f.f( a, b ); } };
/** * Zips this tree with another, using the given function. The resulting tree is the structural intersection * of the two trees. * * @param bs A tree to zip this tree with. * @param f A function with which to zip together the two trees. * @return A new tree of the results of applying the given function over this tree and the given tree, position-wise. */ public <B, C> Tree<C> zipWith(final Tree<B> bs, final F2<A, B, C> f) { return F2Functions.zipTreeM(f).f(this, bs); }
@Override public C f(A a, B b) { return delay.f(() -> rec.f(a, b)); } };
/** * Partial application of the second argument to the supplied function to get a function of type * {@code A -> C}. Same as {@code flip(f).f(b)}. * * @param f The function to partially apply. * @param b The value to apply to the function. * @return A new function based on {@code f} with its second argument applied. */ public static <A, B, C> F<A, C> partialApply2(final F<A, F<B, C>> f, final B b) { return a -> uncurryF2(f).f(a, b); }
/** * Performs function application within a higher-order function (applicative functor pattern). * * @param cab The higher-order function to apply a function to. * @param ca A function to apply within a higher-order function. * @return A new function after applying the given higher-order function to the given function. */ public static <A, B, C> F<C, B> apply(final F2<C, A, B> cab, final F<C, A> ca) { return c -> cab.f(c, ca.f(c)); }
/** * Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. * The structure of the resulting Zipper is the structural intersection of the two Zippers. * * @param bs A Zipper to zip this one with. * @param f A function with which to zip together the two Zippers. * @return The result of applying the given function over this Zipper and the given Zipper, location-wise. */ public <B, C> Zipper<C> zipWith(final Zipper<B> bs, final F2<A, B, C> f) { return F2Functions.zipZipperM(f).f(this, bs); }
/** * Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. * * @param bs A TreeZipper to zip this one with. * @param f A function with which to zip together the two TreeZippers. * @return The result of applying the given function over this TreeZipper and the given TreeZipper, location-wise. */ public <B, C> TreeZipper<C> zipWith(final TreeZipper<B> bs, final F2<A, B, C> f) { return F2Functions.zipTreeZipperM(f).f(this, bs); }
/** * Uncurries this function to a function on tuples. * * @return A new function that calls this function with the elements of a given tuple. */ public static <A, B, C> F<P2<A, B>, C> tuple(final F2<A, B, C> f) { return p -> f.f(p._1(), p._2()); }
@Override <X> X foldl(F2<X, B, X> acc, X init) { return Mu.this.foldl((x, a) -> acc.f(x, f.f(a)), init); } };
@Override <X> X foldr(F2<B, F0<X>, X> cons, X nil) { return Mu.this.foldr((h, t) -> cons.f(f.f(h), t), nil); }