/** * First-class composition flipped. * * @return A function that invokes this function and then a given function on the result. */ public static <A, B, C> F<F<B, C>, F<A, C>> andThen(final F<A, B> f) { return g -> andThen(f, g); }
/** * Function composition flipped. * * @param g A function with which to compose this one. * @return The composed function such that this function is applied first. */ @SuppressWarnings("unchecked") public final <C> F1W<A, C> andThen(final F<B, C> g) { return lift(F1Functions.andThen(this, g)); }
/** * First-class composition flipped. * * @return A function that invokes this function and then a given function on the result. */ public final <C> F1W<F<B, C>, F<A, C>> andThen() { return lift( F1Functions.andThen(this)); }
public final <C> Reader<A, C> map(F<B, C> f) { return unit(F1Functions.andThen(function, f)); }
/** * Promotes this function to return its value in a TreeZipper. * * @return This function promoted to return its value in a TreeZipper. */ public static <A, B> F<A, TreeZipper<B>> treeZipperK(final F<A, B> f) { return andThen(treeK(f), TreeZipper.fromTree()); }
/** * Promotes this function to return its value in a Zipper. * * @return This function promoted to return its value in a Zipper. */ public static <A, B> F<A, Zipper<B>> zipperK(final F<A, B> f) { return andThen(streamK(f), s -> fromStream(s).some()); }
public final A run() { final F<IterV<E, A>, Option<A>> runCont = new F<IterV<E, A>, Option<A>>() { final F<P2<A, Input<E>>, Option<A>> done = F1Functions.andThen(P2.__1(), Option.some_()); final F<F<Input<E>, IterV<E, A>>, Option<A>> cont = Function.constant(Option.none()); @Override public Option<A> f(final IterV<E, A> i) { return i.fold(done, cont); } }; final F<P2<A, Input<E>>, A> done = P2.__1(); final F<F<Input<E>, IterV<E, A>>, A> cont = k -> runCont.f(k.f(Input.eof())).valueE("diverging iteratee"); return fold(done, cont); }