Returns the child node index of the child element at the given path entry, if any, and -1 otherwise.
Returns the child node index of the child element at the given path entry, if any, and -1 otherwise. The faster this method is, the better.
Returns the child nodes of this element, in the correct order
Returns the child nodes of this element, in the correct order
Finds the child element with the given Path.Entry
(where this element is the root), if any, wrapped in an Option
.
Finds the child element with the given Path.Entry
(where this element is the root), if any, wrapped in an Option
.
Returns an element with the same name, attributes and scope as this element, but with the given child nodes
Returns an element with the same name, attributes and scope as this element, but with the given child nodes
Finds the element with the given Path
(where this element is the root), if any, wrapped in an Option
.
Finds the element with the given Path
(where this element is the root), if any, wrapped in an Option
.
This method must be very efficient, which depends on the efficiency of method findChildElemByPathEntry
.
Returns (the equivalent of) findChildElemByPathEntry(entry).get
Returns (the equivalent of) findChildElemByPathEntry(entry).get
Returns (the equivalent of) findElemOrSelfByPath(path).get
Returns (the equivalent of) findElemOrSelfByPath(path).get
Returns a copy in which the child at the given position (0-based) has been removed
Returns a copy in which the child at the given position (0-based) has been removed
Returns a copy in which the given child has been inserted at the end
Returns a copy in which the given child has been inserted at the end
Returns a copy in which the given child has been inserted at the given position (0-based)
Returns a copy in which the given child has been inserted at the given position (0-based)
Returns a copy in which the given child, if any, has been inserted at the end
Returns a copy in which the given child, if any, has been inserted at the end
Returns a copy in which the given child, if any, has been inserted at the given position (0-based)
Returns a copy in which the given child, if any, has been inserted at the given position (0-based)
Returns updated(path) { e => newElem }
Returns updated(path) { e => newElem }
Method that "functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).
Method that "functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).
The method throws an exception if no element is found with the given path.
It can be defined (recursively) as follows:
if (path == Path.Root) f(self) else updated(path.firstEntry) { e => e.updated(path.withoutFirstEntry)(f) }
Core method that "functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).
Core method that "functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).
The method throws an exception if no element is found with the given path entry.
It can be defined as follows:
val idx = self.childNodeIndex(pathEntry)
self.withUpdatedChildren(idx, f(children(idx).asInstanceOf[E]))
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).
It can be defined as follows (ignoring exceptions):
val newChildren = pathEntries.toSeq.map(entry => (entry -> childNodeIndex(entry))).sortBy(_._2).reverse.foldLeft(children) { case (acc, (pathEntry, idx)) => acc.updated(idx, f(acc(idx).asInstanceOf[E], pathEntry)) } withChildren(newChildren)
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant-or-self elements with the given paths (compared to this element as root).
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant-or-self elements with the given paths (compared to this element as root).
It can be defined (recursively) as follows (ignoring exceptions):
def updatedAtPaths(paths: Set[Path])(f: (E, Path) => E): E = { val pathsByPathEntries = paths.filter(path => !path.isRoot).groupBy(path => path.firstEntry) val resultWithoutSelf = self.updatedAtPathEntries(pathsByPathEntries.keySet) { (che, pathEntry) => val newChe = che.updatedAtPaths(paths.map(_.withoutFirstEntry)) { (elem, relativePath) => f(elem, relativePath.prepend(pathEntry)) } newChe } if (paths.contains(Path.Root)) f(resultWithoutSelf, Path.Root) else resultWithoutSelf }
For simple elements, it is also equivalent to:
val pathsReversed = indexed.Elem(this).findAllElemsOrSelf.map(_.path).filter(p => paths.contains(p)).reverse pathsReversed.foldLeft(self) { case (acc, path) => acc.updated(path) { e => f(e, path) } }
Returns updatedWithNodeSeq(path) { e => newNodes }
Returns updatedWithNodeSeq(path) { e => newNodes }
"Functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).
"Functionally updates" the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root). If the given path is the root path, this element itself is returned unchanged.
This function could be defined as follows:
// First define function g as follows: def g(e: Elem): Elem = { if (path == Path.Root) e else { e.withPatchedChildren( e.childNodeIndex(path.lastEntry), f(e.findChildElemByPathEntry(path.lastEntry).get), 1) } } // Then the function updatedWithNodeSeq(path)(f) could be defined as: updated(path.parentPathOption.getOrElse(Path.Root))(g)
After all, this is just a functional update that replaces the parent element, if it exists.
The method throws an exception if no element is found with the given path.
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).
It can be defined as follows (ignoring exceptions):
val indexesByPathEntries = pathEntries.toSeq.map(entry => (entry -> childNodeIndex(entry))).sortBy(_._2).reverse val newChildGroups = indexesByPathEntries.foldLeft(self.children.map(n => immutable.IndexedSeq(n))) { case (acc, (pathEntry, idx)) => acc.updated(idx, f(acc(idx).head.asInstanceOf[E], pathEntry)) } withChildren(newChildGroups.flatten)
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant elements with the given paths (compared to this element as root), but ignoring the root path.
Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant elements with the given paths (compared to this element as root), but ignoring the root path.
It can be defined as follows (ignoring exceptions):
val pathsByParentPaths = paths.filter(path => !path.isRoot).groupBy(path => path.parentPath) self.updatedAtPaths(pathsByParentPaths.keySet) { (elem, path) => val childPathEntries = pathsByParentPaths(path).map(_.lastEntry) elem.updatedWithNodeSeqAtPathEntries(childPathEntries) { (che, pathEntry) => f(che, path.append(pathEntry)) } }
Shorthand for withChildren(children.patch(from, newChildren, replace))
Shorthand for withChildren(children.patch(from, newChildren, replace))
Shorthand for withChildren(children.updated(index, newChild))
Shorthand for withChildren(children.updated(index, newChild))
API and implementation trait for functionally updatable elements. This trait extends trait eu.cdevreeze.yaidom.queryapi.IsNavigable, adding knowledge about child nodes in general, and about the correspondence between child path entries and child indexes.
More precisely, this trait adds the following abstract methods to the abstract methods required by its super-trait:
children
,withChildren
andchildNodeIndex
. Based on these abstract methods (and the super-trait), this trait offers a rich API for functionally updating elements.The purely abstract API offered by this trait is eu.cdevreeze.yaidom.queryapi.UpdatableElemApi. See the documentation of that trait for examples of usage, and for a more formal treatment.
The node supertype of the element subtype
The captured element subtype