/** * Returns the 1-product projection over the second element. * * @return the 1-product projection over the second element. */ public final P1<B> _2_() { return F1Functions.lazy(P2.<A, B>__2()).f(this); }
/** * 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>> p2Ord2(Ord<B> ob) { return on(P2.<A, B>__2(), ob).ord(); }
/** * Polyomorphic lens targeted on _2. */ public static <A, B, C> PLens<P2<A, B>, P2<A, C>, B, C> _2p() { return pLens(__2(), b -> p2 -> P.p(p2._1(), b)); }
/** * Returns an associated value with the given key in the list of pairs. * * @param e The test for equality on keys. * @param x The list of pairs to search. * @param a The key value to find the associated value of. * @return An associated value with the given key in the list of pairs. */ public static <A, B> Option<B> lookup(final Equal<A> e, final List<P2<A, B>> x, final A a) { return x.find(p -> e.eq(p._1(), a)).map(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(); }
/** * Returns the position of the first element matching the given predicate, if any. * * @param p A predicate to match. * @return the position of the first element matching the given predicate, if any. */ public final Option<Integer> indexOf(final F<A, Boolean> p) { return zipIndex().find(p2 -> p.f(p2._1())).map(P2.__2()); }
/** * Returns all values in this tree map. * * @return All values in this tree map. */ public List<V> values() { return iterableList(join(tree.toList().map(compose(IterableW.wrap(), P2.__2())))); }
/** * Splits this TreeMap at the given key. Returns a triple of: * <ul> * <li>A set containing all the values of this map associated with keys less than the given key.</li> * <li>An option of a value mapped to the given key, if it exists in this map, otherwise None. * <li>A set containing all the values of this map associated with keys greater than the given key.</li> * </ul> * * @param k A key at which to split this map. * @return Two sets and an optional value, where all elements in the first set are mapped to keys less than the given * key in this map, all the elements in the second set are mapped to keys greater than the given key, * and the optional value is the value associated with the given key if present, otherwise None. */ public P3<Set<V>, Option<V>, Set<V>> split(Ord<V> ord, final K k) { final F<Set<P2<K, Option<V>>>, Set<V>> getSome = F1Functions.mapSet(F1Functions.o(Option.fromSome(), P2.__2()), ord); return tree.split(p(k, Option.none())).map1(getSome).map3(getSome) .map2(F1Functions.o(Option.join(), F1Functions.mapOption(P2.__2()))); }
P2.<Variable, Variable>__2()).