/** * Creates a {@link P6} by adding the given element to the current {@link P3} * * @param el the element to append * @return A {@link P6} containing the original {@link P3} with the extra element added at the end */ public final <D, E, F> P6<A, B, C, D, E, F> append(P3<D, E, F> el) { return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3()); }
/** * An order instance for a product-3, 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. * @param oc An order instance for the third factor. * @return An order instance for a product-3, with the first factor considered most significant. */ public static <A, B, C> Ord<P3<A, B, C>> p3Ord(final Ord<A> oa, final Ord<B> ob, final Ord<C> oc) { return on(P3.<A, B, C>__1(), oa).then(P3.__2(), ob).then(P3.__3(), oc).ord(); }
/** * Delete the element at the given index. This is an O(log(n)) operation. * * @param i The index of the element to update. * * @return The updated sequence, or throws an error if the index is out of bounds. */ public Seq<A> delete(final int i) { checkBounds(i); final P3<FingerTree<Integer, A>, A, FingerTree<Integer, A>> lxr = ftree.split1(index -> index > i); return new Seq<>(lxr._1().append(lxr._3())); }
/** * Maps the given function across this zipper (covariant functor pattern). * * @param f A function to map across this zipper. * @return A new zipper with the given function applied to the label of every node. */ public <B> TreeZipper<B> map(final F<A, B> f) { final F<Tree<A>, Tree<B>> g = Tree.<A, B>fmap_().f(f); final F<Stream<Tree<A>>, Stream<Tree<B>>> h = Stream.<Tree<A>, Tree<B>>map_().f(g); return treeZipper(tree.fmap(f), lefts.map(g), rights.map(g), parents.map( p -> p.map1(h).map2(f).map3(h))); }
public C _3() { return P3.this._3(); } };
public B _2() { return P3.this._2(); }
public A _1() { return P3.this._1(); }
/** * 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(P3.<A, B, C>__2()).f(this); }
/** * Returns the 1-product projection over the third element. * * @return the 1-product projection over the third element. */ public final P1<C> _3_() { return F1Functions.lazy(P3.<A, B, C>__3()).f(this); }
/** * 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(P3.<A, B, C>__1()).f(this); }
/** * Replace the element at the given index with the supplied value. This is an O(log(n)) operation. * * @param i The index of the element to update. * @param a The new value. * * @return The updated sequence, or throws an error if the index is out of bounds. */ public Seq<A> update(final int i, final A a) { checkBounds(i); final P3<FingerTree<Integer, A>, A, FingerTree<Integer, A>> lxr = ftree.split1(index -> index > i); return new Seq<>(lxr._1().append(lxr._3().cons(a))); }
/** * 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()))); }
public C _3() { return P3.this._3(); } };
public B _2() { return P3.this._2(); }
public A _1() { return P3.this._1(); }
/** * Creates a {@link P4} by adding the given element to the current {@link P3} * * @param el the element to append * @return A {@link P4} containing the original {@link P3} with the extra element added at the end */ public final <D> P4<A, B, C, D> append(D el) { return P.p(_1(), _2(), _3(), el); }
/** * Splits this TreeMap at the given key. Returns a triple of: * <ul> * <li>A tree map 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 tree map 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 tree maps and an optional value, where all keys in the first tree map are mapped * to keys less than the given key in this map, all the keys in the second tree map 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<TreeMap<K, V>, Option<V>, TreeMap<K, V>> splitLookup(final K k) { P3<Set<P2<K, Option<V>>>, Option<P2<K, Option<V>>>, Set<P2<K, Option<V>>>> p3 = tree.split(p(k, get(k))); Ord<K> o = tree.ord().contramap(k2 -> p(k2, Option.none())); return p(treeMap(o, p3._1()), get(k), treeMap(o, p3._3())); }
public X _3() { return f.f(P3.this._3()); } };
public X _2() { return f.f(P3.this._2()); }