private static <K, V> Ord<P2<K, V>> ord(final Ord<K> keyOrd) { return keyOrd.contramap(P2.__1()); }
/** * Returns the 1-product projection over the first element. * * @return the 1-product projection over the first element. */ public final P1<A> _1_() { return F1Functions.lazy(P2.<A, B>__1()).f(this); }
/** * Creates an empty priority queue. * * @param m A monoid to combine node annotations. * @param e A value to compare key equality. */ public static <K, A> PriorityQueue<K, A> empty(Monoid<K> m, Equal<K> e) { return priorityQueue(e, FingerTree.empty(m, P2.__1())); }
/** * Returns all keys in this tree map. * * @return All keys in this tree map. */ public List<K> keys() { return tree.toList().map(P2.__1()); }
/** * Composes this monoid with another. */ public <B> Monoid<P2<A,B>>compose(Monoid<B> m) { return compose(m, P2.__1(), P2.__2(), P::p); }
public static <A, B> Ord<P2<A, B>> p2Ord1(Ord<A> oa) { return on(P2.<A, B>__1(), oa).ord(); }
/** * Polyomorphic lens targeted on _1. */ public static <A, B, C> PLens<P2<A, B>, P2<C, B>, A, C> _1p() { return pLens(__1(), a -> p2 -> P.p(a, p2._2())); }
/** * An order instance for a product-2, with the first factor considered most significant. * * @param oa An order instance for the first factor. * @param ob An order instance for the second factor. * @return An order instance for a product-2, with the first factor considered most significant. */ public static <A, B> Ord<P2<A, B>> p2Ord(final Ord<A> oa, final Ord<B> ob) { return on(P2.<A, B>__1(), oa).then(P2.__2(), ob).ord(); }
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); }
/** * Maps the values in each node with function f. */ public <B> PriorityQueue<K, B> map(F<A, B> f) { return priorityQueue(equal, ftree.map(P2.map2_(f), FingerTree.measured(ftree.measured().monoid(), P2.__1()) ) ); }
/** * Returns all the elements of the queue with the highest (same) priority. */ public List<P2<K, A>> topN() { return toStream().uncons( List.nil(), top -> tail -> List.cons(top, tail._1().takeWhile(compose(equal.eq(top._1()), P2.__1())).toList()) ); }
TreeMap<Variable, Set<Variable>> commonMap = renamingPairs.groupBy(P2.<Variable, Variable>__1(), P2.<Variable, Variable>__2()).
/** * Returns a tuple where the first element is the longest prefix of this stream that satisfies * the given predicate and the second element is the remainder of the stream. * * @param p A predicate to be satisfied by a prefix of this stream. * @return A tuple where the first element is the longest prefix of this stream that satisfies * the given predicate and the second element is the remainder of the stream. */ public final P2<Stream<A>, Stream<A>> span(final F<A, Boolean> p) { if (isEmpty()) return p(this, this); else if (p.f(head())) { final P1<P2<Stream<A>, Stream<A>>> yszs = P.lazy(() -> tail()._1().span(p)); return P.lazy( () -> cons(head(), yszs.map(P2.__1())), () -> yszs._1()._2() ); } else return p(Stream.nil(), this); }