public A _1() { return P3.this._1(); }
public A _1() { return P3.this._1(); }
public X _1() { return f.f(P3.this._1()); }
/** * 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()); }
/** * 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); }
/** * Creates a new Zipper from the given triple. * * @param p A triple of the elements before the focus, the focus element, and the elements after the focus, * respectively. * @return a new Zipper created from the given triple. */ public static <A> Zipper<A> zipper(final P3<Stream<A>, A, Stream<A>> p) { return new Zipper<>(p._1(), p._2(), p._3()); }
/** * An equal instance for a product-3. * * @param ea Equality across the first element of the product. * @param eb Equality across the second element of the product. * @param ec Equality across the third element of the product. * @return An equal instance for a product-3. */ public static <A, B, C> Equal<P3<A, B, C>> p3Equal(final Equal<A> ea, final Equal<B> eb, final Equal<C> ec) { Definition<A> eaDef = ea.def; Definition<B> ebDef = eb.def; Definition<C> ecDef = ec.def; return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3())); }
/** * 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())); }
/** * 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()); }
/** * 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))); }
/** * Creates a {@link P7} by adding the given element to the current {@link P3} * * @param el the element to append * @return A {@link P7} containing the original {@link P3} with the extra element added at the end */ public final <D, E, F, G> P7<A, B, C, D, E, F, G> append(P4<D, E, F, G> el) { return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4()); }
/** * Creates a {@link P7} by adding the given element to the current {@link P4} * * @param el the element to append * @return A {@link P7} containing the original {@link P4} with the extra element added at the end */ public final <E, F, G> P7<A, B, C, D, E, F, G> append(P3<E, F, G> el) { return P.p(_1(), _2(), _3(), _4(), el._1(), el._2(), el._3()); }
/** * Creates a {@link P8} by adding the given element to the current {@link P5} * * @param el the element to append * @return A {@link P8} containing the original {@link P5} with the extra element added at the end */ public final <F, G, H> P8<A, B, C, D, E, F, G, H> append(P3<F, G, H> el) { return P.p(_1(), _2(), _3(), _4(), _5(), el._1(), el._2(), el._3()); }
/** * Creates a {@link P8} by adding the given element to the current {@link P3} * * @param el the element to append * @return A {@link P8} containing the original {@link P3} with the extra element added at the end */ public final <D, E, F, G, H> P8<A, B, C, D, E, F, G, H> append(P5<D, E, F, G, H> el) { return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4(), el._5()); }
/** * Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, * changes from <code>false</code> to <code>true</code>. This is a O(log(n)) operation. * * @return Pair: the subtree containing elements before the point where <code>pred</code> first holds and the subtree * containing element at and after the point where <code>pred</code> first holds. Empty if <code>pred</code> never holds. */ public final P2<FingerTree<V, A>, FingerTree<V, A>> split(final F<V, Boolean> predicate) { if (!isEmpty() && predicate.f(measure())) { final P3<FingerTree<V, A>, A, FingerTree<V, A>> lxr = split1(predicate); return P.p(lxr._1(), lxr._3().cons(lxr._2())); } else { return P.p(this, mkTree(m).empty()); } }
/** * Navigates to the parent of the current location. * * @return A new tree zipper focused on the parent node of the current node, * or none if the current node is the root node. */ public Option<TreeZipper<A>> parent() { if (parents.isEmpty()) return none(); else { final P3<Stream<Tree<A>>, A, Stream<Tree<A>>> p = parents.head(); return some(treeZipper(node(p._2(), combChildren(lefts, tree, rights)), p._1(), p._3(), parents.tail()._1())); } }
/** * A show instance for the {@link P3 tuple-3} type. * * @param sa Show for the first element of the tuple. * @param sb Show for the second element of the tuple. * @param sc Show for the third element of the tuple. * @return A show instance for the {@link P3 tuple-3} type. */ public static <A, B, C> Show<P3<A, B, C>> p3Show(final Show<A> sa, final Show<B> sb, final Show<C> sc) { return show(p -> cons('(', p(sa.show(p._1()))).snoc(',').append(sb.show(p._2())).snoc(',') .append(sc.show(p._3())).snoc(')')); }
/** * Returns true if this set is a subset of the given set. * * @param s A set which is a superset of this set if this method returns true. * @return true if this set is a subset of the given set. */ public final boolean subsetOf(final Set<A> s) { if (isEmpty() || s.isEmpty()) return isEmpty(); else { final P3<Set<A>, Option<A>, Set<A>> find = s.split(head()); return find._2().isSome() && l().subsetOf(find._1()) && r().subsetOf(find._3()); } }
/** * Maps a function across a TreeZipper in parallel. * * @param za A TreeZipper to map across in parallel. * @param f A function to map across the given TreeZipper. * @return A promise of a new TreeZipper with the given function applied to each element of the tree. */ public <A, B> Promise<TreeZipper<B>> parMap(final TreeZipper<A> za, final F<A, B> f) { final F<Tree<A>, Tree<B>> tf = Tree.<A, B>fmap_().f(f); final P4<Tree<A>, Stream<Tree<A>>, Stream<Tree<A>>, Stream<P3<Stream<Tree<A>>, A, Stream<Tree<A>>>>> p = za.p(); return mapM(p._4(), p3 -> parMap(p3._3(), tf).apply(promise(f).f(p3._2()).apply( parMap(p3._1(), tf).fmap(P.p3())))).apply(parMap(za.rights(), tf).apply( parMap(za.lefts(), tf).apply(parMap(p._1(), f).fmap(TreeZipper.treeZipper())))); }