/** * Returns the second element of this vector. * * @return the second element of this vector. */ public A _2() { return inner._2(); }
/** * Creates a {@link P4} by adding the given element to the current {@link P2} * * @param el the element to append * @return A {@link P4} containing the original {@link P2} with the extra element added at the end */ public final <C, D> P4<A, B, C, D> append(P2<C, D> el) { return P.p(_1(), _2(), el._1(), el._2()); }
/** * 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()); }
/** * Creates a {@link P3} by adding the given element to the current {@link P2} * * @param el the element to append * @return A {@link P3} containing the original {@link P2} with the extra element added at the end */ public final <C> P3<A, B, C> append(C el) { return P.p(_1(), _2(), el); }
/** * Map the second element of the product. * * @param f The function to map with. * @return A product with the given function applied. */ public final <X> P2<A, X> map2(final F<B, X> f) { return P.lazy(P2.this::_1, () -> f.f(P2.this._2())); }
/** * Adds a node with priority k and value a. This operation take O(1). */ public PriorityQueue<K, A> enqueue(P2<K, A> p) { return enqueue(p._1(), p._2()); }
public final P2<Rng, Integer> nextInt() { P2<Rng, Long> p = nextLong(); int i = (int) p._2().longValue(); return P.p(p._1(), i); }
/** * Transforms a curried function of arity-2 to a function of a product-2 * * @param f a curried function of arity-2 to transform into a function of a product-2 * @return The function, transformed to operate on on a product-2 */ public static <A, B, C> F<P2<A, B>, C> tuple(final F<A, F<B, C>> f) { return p -> f.f(p._1()).f(p._2()); }
/** * Removes the first element that equals the given object. * To remove all matches, use <code>removeAll(e.eq(a))</code> * * @param a The element to remove * @param e An <code>Equals</code> instance for the element's type. * @return A new list whose elements do not match the given predicate. */ public final List<A> delete(final A a, final Equal<A> e) { final P2<List<A>, List<A>> p = span(compose(not, e.eq(a))); return p._2().isEmpty() ? p._1() : p._1().append(p._2().tail()); }
/** * Returns the minimum (key, value) pair in the tree if the tree is not empty. */ public Option<P2<K, V>> min() { return tree.min().map(p -> p(p._1(), p._2().some())); }
/** * Splits this sequence into a pair of sequences at the given position. This is a O(log(n)) operation. * * @return Pair: the subsequence containing elements with indices less than <code>i</code> * and the subsequence containing elements with indices greater than or equal to <code>i</code>. */ public P2<Seq<A>, Seq<A>> split(final int i) { final P2<FingerTree<Integer, A>, FingerTree<Integer, A>> lr = ftree.split(index -> index > i); return P.p(new Seq<>(lr._1()), new Seq<>(lr._2())); }
/** * Creates a {@link P5} by adding the given element to the current {@link P2} * * @param el the element to append * @return A {@link P5} containing the original {@link P2} with the extra element added at the end */ public final <C, D, E> P5<A, B, C, D, E> append(P3<C, D, E> el) { return P.p(_1(), _2(), el._1(), el._2(), el._3()); }
/** * Creates a {@link P5} by adding the given element to the current {@link P3} * * @param el the element to append * @return A {@link P5} containing the original {@link P3} with the extra element added at the end */ public final <D, E> P5<A, B, C, D, E> append(P2<D, E> el) { return P.p(_1(), _2(), _3(), el._1(), el._2()); }
/** * Transforms a non empty list of pairs into a non empty list of first components and * a non empty list of second components. * * @param xs The non empty list of pairs to transform. * @return A non empty list of first components and a non empty list of second components. */ public static <A, B> P2<NonEmptyList<A>, NonEmptyList<B>> unzip(final NonEmptyList<P2<A, B>> xs) { final P2<List<A>, List<B>> p = List.unzip(xs.toList()); return P.p(nel(p._1().head(), p._1().tail()), nel(p._2().head(), p._2().tail())); }
/** * Creates a {@link P6} by adding the given element to the current {@link P4} * * @param el the element to append * @return A {@link P6} containing the original {@link P4} with the extra element added at the end */ public final <E, F> P6<A, B, C, D, E, F> append(P2<E, F> el) { return P.p(_1(), _2(), _3(), _4(), el._1(), el._2()); }
/** * Transforms a stream of pairs into a stream of first components and a stream of second components. * * @param xs The stream of pairs to transform. * @return A stream of first components and a stream of second components. */ public static <A, B> P2<Stream<A>, Stream<B>> unzip(final Stream<P2<A, B>> xs) { return xs.foldRight((p, ps) -> { final P2<Stream<A>, Stream<B>> pp = ps._1(); return p(cons(p._1(), p(pp._1())), cons(p._2(), p(pp._2()))); }, p(Stream.nil(), Stream.nil())); }
/** * Builds a tree from a seed value. * * @param f A function with which to build the tree. * @return A function which, given a seed value, yields a tree. */ public static <A, B> F<B, Tree<A>> unfoldTree(final F<B, P2<A, P1<Stream<B>>>> f) { return b -> { final P2<A, P1<Stream<B>>> p = f.f(b); return node(p._1(), p._2().map(Stream.<B, Tree<A>>map_().f(unfoldTree(f)))); }; }
/** * Creates a {@link P7} by adding the given element to the current {@link P2} * * @param el the element to append * @return A {@link P7} containing the original {@link P2} with the extra element added at the end */ public final <C, D, E, F, G> P7<A, B, C, D, E, F, G> append(P5<C, D, E, F, G> el) { return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4(), el._5()); }