/** * A first-class version of the split function. * * @param f A function that will map the first element of the given product. * @param g A function that will map the second element of the given product. * @return A function that splits a given product between the two given functions and combines their output. */ public static <A, B, C, D> F<P2<A, B>, P2<C, D>> split_(final F<A, C> f, final F<B, D> g) { return p -> p.split(f, g); }
/** * Maps the given function across both the elements of the given product. * * @param f A function to map over a product. * @param p A product over which to map. * @return A new product with the given function applied to both elements. */ public static <A, B> P2<B, B> map(final F<A, B> f, final P2<A, A> p) { return p.split(f, f); }
/** * Maps the given function across this vector. * * @param f The function to map across this vector. * @return A new vector after the given function has been applied to each element. */ public <B> V2<B> map(final F<A, B> f) { return p(inner.split(f, f)); }
/** * Performs function application within a vector (applicative functor pattern). * * @param vf The vector of functions to apply. * @return A new vector after zipping the given vector of functions over this vector. */ public <B> V2<B> apply(final V2<F<A, B>> vf) { return p(inner.split(vf._1(), vf._2())); }
/** * Sends the given input value to both argument functions and combines their output. * * @param f A function to receive an input value. * @param g A function to receive an input value. * @param b An input value to send to both functions. * @return The product of the two functions applied to the input value. */ public static <B, C, D> P2<C, D> fanout(final F<B, C> f, final F<B, D> g, final B b) { return join(P.<B, B>p2()).f(b).split(f, g); }