/** * An order instance for a product-1. * * @param oa Order across the produced type. * @return An order instance for a product-1. */ public static <A> Ord<P1<A>> p1Ord(final Ord<A> oa) { return oa.contramap(P1.__1()); }
/** * A hash instance for a product-1. * * @param ha A hash for the first element of the product. * @return A hash instance for a product-1. */ public static <A> Hash<P1<A>> p1Hash(final Hash<A> ha) { return ha.contramap(P1.__1()); }
/** * An equal instance for a product-1. * * @param ea Equality across the first element of the product. * @return An equal instance for a product-1. */ public static <A> Equal<P1<A>> p1Equal(final Equal<A> ea) { return ea.contramap(P1.__1()); }
/** * Turns an array of P1s into a single P1 of an array. * * @param as The array of P1s to transform. * @return A single P1 for the given array. */ public static <A> P1<Array<A>> sequence(final Array<P1<A>> as) { return P.lazy(() -> as.map(P1.__1())); }
/** * A strict version of parMap over lists. * Maps the given function over the given list in parallel using this strategy, * blocking the current thread until all values have been obtained. * * @param f A function to map over the given list in parallel. * @param bs A list over which to map the given function in parallel. * @return A list with all of its elements transformed by the given function. */ public <B> List<A> parMap1(final F<B, A> f, final List<B> bs) { return compose(P1.__1(), parMapList(f)).f(bs); }
/** * A strict version of parMap over arrays. * Maps the given function over the given arrays in parallel using this strategy, * blocking the current thread until all values have been obtained. * * @param f A function to map over the given array in parallel. * @param bs An array over which to map the given function in parallel. * @return An array with all of its elements transformed by the given function. */ public <B> Array<A> parMap1(final F<B, A> f, final Array<B> bs) { return compose(P1.__1(), parMapArray(f)).f(bs); }
@Override public P1<A> sum(P1<A> ap1, F0<Stream<P1<A>>> as) { return P.lazy(() -> def.sum(ap1._1(), () -> as.f().map(P1.__1()))); } });
/** * Performs a right-fold reduction across this zipper. * * @param f The function to apply on each element of this zipper. * @param z The beginning value to start the application from. * @return the final result after the right-fold reduction. */ public <B> B foldRight(final F<A, F<B, B>> f, final B z) { return left.foldLeft(flip(f), right.cons(focus).foldRight(compose( Function.<P1<B>, B, B>andThen().f(P1.__1()), f), z)); }
/** * Provides a stream of the elements of the tree at each level, in level order. * * @return The elements of the tree at each level. */ public Stream<Stream<A>> levels() { final F<Stream<Tree<A>>, Stream<Tree<A>>> flatSubForests = Stream.<Tree<A>, Tree<A>>bind_().f(compose(P1.__1(), Tree.subForest_())); final F<Stream<Tree<A>>, Stream<A>> roots = Stream.<Tree<A>, A>map_().f(Tree.root_()); return iterateWhile(flatSubForests, Stream.isNotEmpty_(), single(this)).map(roots); }