@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); }
/** * 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)); }
/** * 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); }
/** * Performs a left-fold reduction across this list. This function runs in constant space. */ public final A foldLeft1(final F2<A, A, A> f) { A x = head; for (List<A> xs = tail; !xs.isEmpty(); xs = xs.tail()) { x = f.f(x, xs.head()); } return x; }
/** * Performs a reduction on this finger tree using the given arguments. * * @param nil The value to return if this finger tree is empty. * @param cons The function to apply to the head and tail of this finger tree if it is not empty. * @return A reduction on this finger tree. */ public final <B> B uncons(B nil, F2<A, FingerTree<V, A>, B> cons) { return isEmpty() ? nil : cons.f(head(), tail()); }
/** * Performs a right-fold reduction across this stream. This function uses O(length) stack space. * * @param f The function to apply on each element of the stream. * @param b The beginning value to start the application from. * @return The final result after the right-fold reduction. */ public final <B> B foldRight1(final F2<A, B, B> f, final B b) { return isEmpty() ? b : f.f(head(), tail()._1().foldRight1(f, b)); }
/** * Performs a right-fold reduction across this stream. This function uses O(length) stack space. * * @param f The function to apply on each element of the stream. * @param b The beginning value to start the application from. * @return The final result after the right-fold reduction. */ public final <B> B foldRight(final F2<A, P1<B>, B> f, final B b) { return isEmpty() ? b : f.f(head(), P.lazy(() -> tail()._1().foldRight(f, b))); }
@Override public C sum(F0<Stream<C>> cs) { return c.f(maDef.sum(() -> cs.f().map(a)), mbDef.sum(() -> cs.f().map(b))); } });
@Override public F<C, C> prepend(C c1) { F<A, A> prependA = saDef.prepend(a.f(c1)); F<B, B> prependB = sbDef.prepend(b.f(c1)); return c2 -> c.f(prependA.f(a.f(c2)), prependB.f(b.f(c2))); }
@Override public F<C, C> prepend(C c1) { F<A, A> prependA = maDef.prepend(a.f(c1)); F<B, B> prependB = mbDef.prepend(b.f(c1)); return c2 -> c.f(prependA.f(a.f(c2)), prependB.f(b.f(c2))); }