/** * 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))); }
/** * 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()))); }