Trait/Object

eu.cdevreeze.yaidom.queryapi

UpdatableElemApi

Related Docs: object UpdatableElemApi | package queryapi

Permalink

trait UpdatableElemApi extends AnyElemNodeApi with IsNavigableApi

This is the functional update part of the yaidom uniform query API. It is a sub-trait of trait eu.cdevreeze.yaidom.queryapi.IsNavigableApi. Only a few DOM-like element implementations in yaidom mix in this trait (indirectly, because some implementing sub-trait is mixed in), thus sharing this query API.

This trait typically does not show up in application code using yaidom, yet its (uniform) API does. Hence, it makes sense to read the documentation of this trait, knowing that the API is offered by multiple element implementations.

This trait is purely abstract. The most common implementation of this trait is eu.cdevreeze.yaidom.queryapi.UpdatableElemLike. The trait has all the knowledge of its super-trait, but in addition to that knows the following:

Obviously methods children, withChildren and collectChildNodeIndexes must be consistent with methods such as findAllChildElems.

Using this minimal knowledge alone, trait UpdatableElemLike not only offers the methods of its parent trait, but also:

For the conceptual difference with "transformable" elements, see trait eu.cdevreeze.yaidom.queryapi.TransformableElemApi.

This query API leverages the Scala Collections API. Query results can be manipulated using the Collections API, and the query API implementation (in UpdatableElemLike) uses the Collections API internally.

UpdatableElemApi examples

To illustrate the use of this API, consider the following example XML:

<book:Bookstore xmlns:book="http://bookstore/book" xmlns:auth="http://bookstore/author">
  <book:Book ISBN="978-0321356680" Price="35" Edition="2">
    <book:Title>Effective Java (2nd Edition)</book:Title>
    <book:Authors>
      <auth:Author>
        <auth:First_Name>Joshua</auth:First_Name>
        <auth:Last_Name>Bloch</auth:Last_Name>
      </auth:Author>
    </book:Authors>
  </book:Book>
  <book:Book ISBN="978-0981531649" Price="35" Edition="2">
    <book:Title>Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition</book:Title>
    <book:Authors>
      <auth:Author>
        <auth:First_Name>Martin</auth:First_Name>
        <auth:Last_Name>Odersky</auth:Last_Name>
      </auth:Author>
      <auth:Author>
        <auth:First_Name>Lex</auth:First_Name>
        <auth:Last_Name>Spoon</auth:Last_Name>
      </auth:Author>
      <auth:Author>
        <auth:First_Name>Bill</auth:First_Name>
        <auth:Last_Name>Venners</auth:Last_Name>
      </auth:Author>
    </book:Authors>
  </book:Book>
</book:Bookstore>

Suppose this XML has been parsed into eu.cdevreeze.yaidom.simple.Elem variable named bookstoreElem. Then we can add a book as follows, where we "forget" the 2nd author for the moment:

import convert.ScalaXmlConversions._

val bookstoreNamespace = "http://bookstore/book"
val authorNamespace = "http://bookstore/author"

val fpBookXml =
  <book:Book xmlns:book="http://bookstore/book" xmlns:auth="http://bookstore/author" ISBN="978-1617290657" Price="33">
    <book:Title>Functional Programming in Scala</book:Title>
    <book:Authors>
      <auth:Author>
        <auth:First_Name>Paul</auth:First_Name>
        <auth:Last_Name>Chiusano</auth:Last_Name>
      </auth:Author>
    </book:Authors>
  </book:Book>
val fpBookElem = convertToElem(fpBookXml)

bookstoreElem = bookstoreElem.plusChild(fpBookElem)

Note that the namespace declarations for prefixes book and auth had to be repeated in the Scala XML literal for the added book, because otherwise the convertToElem method would throw an exception (since Elem instances cannot be created unless all element and attribute QNames can be resolved as ENames).

The resulting bookstore seems ok, but if we print convertElem(bookstoreElem), the result does not look pretty. This can be fixed if the last assignment is replaced by:

bookstoreElem = bookstoreElem.plusChild(fpBookElem).prettify(2)

knowing that an indentation of 2 spaces has been used throughout the original XML. Method prettify is expensive, so it is best not to invoke it within a tight loop. As an alternative, formatting can be left to the DocumentPrinter, of course.

The assignment above is the same as the following one:

bookstoreElem = bookstoreElem.withChildren(bookstoreElem.children :+ fpBookElem).prettify(2)

There are several methods to functionally update the children of an element. For example, method plusChild is overloaded, and the other variant can insert a child at a given 0-based position. Other "children update" methods are minusChild, withPatchedChildren and withUpdatedChildren.

Let's now turn to functional update methods that take Path instances or collections thereof. In the example above the second author of the added book is missing. Let's fix that:

val secondAuthorXml =
  <auth:Author xmlns:auth="http://bookstore/author">
    <auth:First_Name>Runar</auth:First_Name>
    <auth:Last_Name>Bjarnason</auth:Last_Name>
  </auth:Author>
val secondAuthorElem = convertToElem(secondAuthorXml)

val fpBookAuthorsPaths =
  for {
    authorsPath <- indexed.Elem(bookstoreElem) filterElems { e => e.resolvedName == EName(bookstoreNamespace, "Authors") } map (_.path)
    if authorsPath.findAncestorPath(path => path.endsWithName(EName(bookstoreNamespace, "Book")) &&
      bookstoreElem.getElemOrSelfByPath(path).attribute(EName("ISBN")) == "978-1617290657").isDefined
  } yield authorsPath

require(fpBookAuthorsPaths.size == 1)
val fpBookAuthorsPath = fpBookAuthorsPaths.head

bookstoreElem = bookstoreElem.updateElemOrSelf(fpBookAuthorsPath) { elem =>
  require(elem.resolvedName == EName(bookstoreNamespace, "Authors"))
  val rawResult = elem.plusChild(secondAuthorElem)
  rawResult transformElemsOrSelf (e => e.copy(scope = elem.scope.withoutDefaultNamespace ++ e.scope))
}
bookstoreElem = bookstoreElem.prettify(2)

Clearly the resulting bookstore element is nicely formatted, but there was another possible issue that was taken into account. See the line of code transforming the "raw result". That line was added in order to prevent namespace undeclarations, which for XML version 1.0 are not allowed (with the exception of the default namespace). After all, the XML for the second author was created with only the auth namespace declared. Without the above-mentioned line of code, a namespace undeclaration for prefix book would have occurred in the resulting XML, thus leading to an invalid XML 1.0 element tree.

To illustrate functional update methods taking collections of paths, let's remove the added book from the book store. Here is one (somewhat inefficient) way to do that:

val bookPaths = indexed.Elem(bookstoreElem) filterElems (_.resolvedName == EName(bookstoreNamespace, "Book")) map (_.path)

bookstoreElem = bookstoreElem.updateElemsWithNodeSeq(bookPaths.toSet) { (elem, path) =>
  if ((elem \@ EName("ISBN")).contains("978-1617290657")) Vector() else Vector(elem)
}
bookstoreElem = bookstoreElem.prettify(2)

There are very many ways to write this functional update, using different functional update methods in trait UpdatableElemApi, or even only using transformation methods in trait TransformableElemApi (thus not using paths).

The example code above is enough to get started using the UpdatableElemApi methods, but it makes sense to study the entire API, and practice with it. Always keep in mind that functional updates typically mess up formatting and/or namespace (un)declarations, unless these aspects are taken into account.

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. UpdatableElemApi
  2. IsNavigableApi
  3. AnyElemNodeApi
  4. AnyElemApi
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type ThisElem <: UpdatableElemApi

    Permalink

    The element type itself.

    The element type itself. It must be restricted to a sub-type of the query API trait in question.

    Concrete element classes will restrict this type to that element class itself.

    Definition Classes
    UpdatableElemApiIsNavigableApiAnyElemApi
  2. abstract type ThisNode >: ThisElem

    Permalink

    The node type, that is a super-type of the element type, but also of corresponding text node types etc.

    The node type, that is a super-type of the element type, but also of corresponding text node types etc.

    Definition Classes
    AnyElemNodeApi

Abstract Value Members

  1. abstract def childNodeIndex(pathEntry: Entry): Int

    Permalink

    Finds the child node index of the given path entry, or -1 if not found.

    Finds the child node index of the given path entry, or -1 if not found. More precisely, returns:

    collectChildNodeIndexes(Set(pathEntry)).getOrElse(pathEntry, -1)
  2. abstract def children: IndexedSeq[ThisNode]

    Permalink

    Returns the child nodes of this element, in the correct order

  3. abstract def collectChildNodeIndexes(pathEntries: Set[Entry]): Map[Entry, Int]

    Permalink

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes.

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes. The result Map has no entries for path entries that cannot be resolved. This method should be fast, especially if the passed path entry set is small.

  4. abstract def findAllChildElemsWithPathEntries: IndexedSeq[(ThisElem, Entry)]

    Permalink

    Returns all child elements paired with their path entries.

    Returns all child elements paired with their path entries.

    Definition Classes
    IsNavigableApi
  5. abstract def findChildElemByPathEntry(entry: Entry): Option[ThisElem]

    Permalink

    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.

    Typically this method must be very efficient, in order for methods like findElemOrSelfByPath to be efficient.

    Definition Classes
    IsNavigableApi
  6. abstract def findElemOrSelfByPath(path: Path): Option[ThisElem]

    Permalink

    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.

    That is, returns:

    findReverseAncestryOrSelfByPath(path).map(_.last)

    Note that for each non-empty Path, we have:

    findElemOrSelfByPath(path) ==
      findChildElemByPathEntry(path.firstEntry).
        flatMap(_.findElemOrSelfByPath(path.withoutFirstEntry))
    Definition Classes
    IsNavigableApi
  7. abstract def findReverseAncestryOrSelfByPath(path: Path): Option[IndexedSeq[ThisElem]]

    Permalink

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option.

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option. None is returned if no element can be found at the given Path.

    Hence, the resulting element collection, if any, starts with this element and ends with the element at the given Path, relative to this element.

    This method comes in handy for (efficiently) computing base URIs, where the (reverse) ancestry-or-self is needed as input.

    Definition Classes
    IsNavigableApi
  8. abstract def getChildElemByPathEntry(entry: Entry): ThisElem

    Permalink

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Definition Classes
    IsNavigableApi
  9. abstract def getElemOrSelfByPath(path: Path): ThisElem

    Permalink

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Definition Classes
    IsNavigableApi
  10. abstract def getReverseAncestryOrSelfByPath(path: Path): IndexedSeq[ThisElem]

    Permalink

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Definition Classes
    IsNavigableApi
  11. abstract def minusChild(index: Int): ThisElem

    Permalink

    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. Throws an exception if index >= children.size.

  12. abstract def plusChild(child: ThisNode): ThisElem

    Permalink

    Returns a copy in which the given child has been inserted at the end

  13. abstract def plusChild(index: Int, child: ThisNode): ThisElem

    Permalink

    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). If index == children.size, adds the element at the end. If index > children.size, throws an exception.

    Afterwards, the resulting element indeed has the given child at position index (0-based).

  14. abstract def plusChildOption(childOption: Option[ThisNode]): ThisElem

    Permalink

    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. That is, returns plusChild(childOption.get) if the given optional child element is non-empty.

  15. abstract def plusChildOption(index: Int, childOption: Option[ThisNode]): ThisElem

    Permalink

    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). That is, returns plusChild(index, childOption.get) if the given optional child element is non-empty.

  16. abstract def plusChildren(childSeq: IndexedSeq[ThisNode]): ThisElem

    Permalink

    Returns a copy in which the given children have been inserted at the end

  17. abstract def thisElem: ThisElem

    Permalink

    This element itself.

    This element itself.

    Definition Classes
    AnyElemApi
  18. abstract def updateChildElem(pathEntry: Entry, newElem: ThisElem): ThisElem

    Permalink

    Returns updateChildElem(pathEntry) { e => newElem }

  19. abstract def updateChildElem(pathEntry: Entry)(f: (ThisElem) ⇒ ThisElem): ThisElem

    Permalink

    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).

    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).

    It can be defined as follows:

    updateChildElems(Set(pathEntry)) { case (che, pe) => f(che) }
  20. abstract def updateChildElemWithNodeSeq(pathEntry: Entry, newNodes: IndexedSeq[ThisNode]): ThisElem

    Permalink

    Returns updateChildElemWithNodeSeq(pathEntry) { e => newNodes }

  21. abstract def updateChildElemWithNodeSeq(pathEntry: Entry)(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): ThisElem

    Permalink

    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).

    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).

    It can be defined as follows:

    updateChildElemsWithNodeSeq(Set(pathEntry)) { case (che, pe) => f(che) }
  22. abstract def updateChildElems(f: (ThisElem, Entry) ⇒ Option[ThisElem]): ThisElem

    Permalink

    Invokes updateChildElems, passing the path entries for which the passed function is defined.

    Invokes updateChildElems, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, ThisElem] =
      findAllChildElemsWithPathEntries.flatMap({ case (che, pe) =>
        f(che, pe).map(newE => (pe, newE)) }).toMap
    
    updateChildElems(editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, che) }
  23. abstract def updateChildElems(pathEntries: Set[Entry])(f: (ThisElem, Entry) ⇒ ThisElem): ThisElem

    Permalink

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function.

    That is, returns the equivalent of:

    updateChildElemsWithNodeSeq(pathEntries) { case (che, pe) => Vector(f(che, pe)) }

    If the set of path entries is small, this method is rather efficient.

  24. abstract def updateChildElemsWithNodeSeq(f: (ThisElem, Entry) ⇒ Option[IndexedSeq[ThisNode]]): ThisElem

    Permalink

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined.

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, immutable.IndexedSeq[ThisNode]] =
      findAllChildElemsWithPathEntries.flatMap({ case (che, pe) =>
        f(che, pe).map(newNodes => (pe, newNodes)) }).toMap
    
    updateChildElemsWithNodeSeq(editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, immutable.IndexedSeq(che))
    }
  25. abstract def updateChildElemsWithNodeSeq(pathEntries: Set[Entry])(f: (ThisElem, Entry) ⇒ IndexedSeq[ThisNode]): ThisElem

    Permalink

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function. This is the core method of the update API, and the other methods have implementations that directly or indirectly depend on this method.

    That is, returns:

    if (pathEntries.isEmpty) self
    else {
      val indexesByPathEntries: Seq[(Path.Entry, Int)] =
        collectChildNodeIndexes(pathEntries).toSeq.sortBy(_._2)
    
      // Updating in reverse order of indexes, in order not to invalidate the path entries
      val newChildren = indexesByPathEntries.reverse.foldLeft(self.children) {
        case (accChildNodes, (pathEntry, idx)) =>
          val che = accChildNodes(idx).asInstanceOf[ThisElem]
          accChildNodes.patch(idx, f(che, pathEntry), 1)
      }
      self.withChildren(newChildren)
    }

    If the set of path entries is small, this method is rather efficient.

  26. abstract def updateElemOrSelf(path: Path, newElem: ThisElem): ThisElem

    Permalink

    Returns updateElemOrSelf(path) { e => newElem }

  27. abstract def updateElemOrSelf(path: Path)(f: (ThisElem) ⇒ ThisElem): ThisElem

    Permalink

    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).

    It can be defined as follows:

    updateElemsOrSelf(Set(path)) { case (e, path) => f(e) }
  28. abstract def updateElemWithNodeSeq(path: Path, newNodes: IndexedSeq[ThisNode]): ThisElem

    Permalink

    Returns updateElemWithNodeSeq(path) { e => newNodes }

  29. abstract def updateElemWithNodeSeq(path: Path)(f: (ThisElem) ⇒ IndexedSeq[ThisNode]): ThisElem

    Permalink

    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:

    updateElemsWithNodeSeq(Set(path)) { case (e, path) => f(e) }
  30. abstract def updateElems(paths: Set[Path])(f: (ThisElem, Path) ⇒ ThisElem): ThisElem

    Permalink

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElems(pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        che.updateElemsOrSelf(pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

  31. abstract def updateElemsOrSelf(paths: Set[Path])(f: (ThisElem, Path) ⇒ ThisElem): ThisElem

    Permalink

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElems(pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          che.updateElemsOrSelf(pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    In other words, returns:

    val descendantUpdateResult = updateElems(paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    If the set of paths is small, this method is rather efficient.

  32. abstract def updateElemsOrSelfWithNodeSeq(paths: Set[Path])(f: (ThisElem, Path) ⇒ IndexedSeq[ThisNode]): IndexedSeq[ThisNode]

    Permalink

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElemsWithNodeSeq(pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          che.updateElemsOrSelfWithNodeSeq(
            pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    In other words, returns:

    val descendantUpdateResult = updateElemsWithNodeSeq(paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    If the set of paths is small, this method is rather efficient.

  33. abstract def updateElemsWithNodeSeq(paths: Set[Path])(f: (ThisElem, Path) ⇒ IndexedSeq[ThisNode]): ThisElem

    Permalink

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElemsWithNodeSeq(pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        che.updateElemsOrSelfWithNodeSeq(
          pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

  34. abstract def updateTopmostElems(f: (ThisElem, Path) ⇒ Option[ThisElem]): ThisElem

    Permalink

    Invokes updateElems, passing the topmost non-empty paths for which the passed function is defined.

    Invokes updateElems, passing the topmost non-empty paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, ThisElem]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElems { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElems(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, elm)
    }
  35. abstract def updateTopmostElemsOrSelf(f: (ThisElem, Path) ⇒ Option[ThisElem]): ThisElem

    Permalink

    Invokes updateElemsOrSelf, passing the topmost paths for which the passed function is defined.

    Invokes updateElemsOrSelf, passing the topmost paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, ThisElem]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElemsOrSelf { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsOrSelf(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, elm)
    }
  36. abstract def updateTopmostElemsOrSelfWithNodeSeq(f: (ThisElem, Path) ⇒ Option[IndexedSeq[ThisNode]]): IndexedSeq[ThisNode]

    Permalink

    Invokes updateElemsOrSelfWithNodeSeq, passing the topmost paths for which the passed function is defined.

    Invokes updateElemsOrSelfWithNodeSeq, passing the topmost paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, immutable.IndexedSeq[ThisNode]]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElemsOrSelf { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsOrSelfWithNodeSeq(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, immutable.IndexedSeq(elm))
    }
  37. abstract def updateTopmostElemsWithNodeSeq(f: (ThisElem, Path) ⇒ Option[IndexedSeq[ThisNode]]): ThisElem

    Permalink

    Invokes updateElemsWithNodeSeq, passing the topmost non-empty paths for which the passed function is defined.

    Invokes updateElemsWithNodeSeq, passing the topmost non-empty paths for which the passed function is defined. It is equivalent to:

    val mutableEditsByPaths = mutable.Map[Path, immutable.IndexedSeq[ThisNode]]()
    
    val foundElems =
      ElemWithPath(self) findTopmostElems { elm =>
        val optResult = f(elm.elem, elm.path)
        if (optResult.isDefined) {
          mutableEditsByPaths += (elm.path -> optResult.get)
        }
        optResult.isDefined
      }
    
    val editsByPaths = mutableEditsByPaths.toMap
    
    updateElemsWithNodeSeq(editsByPaths.keySet) {
      case (elm, path) => editsByPaths.getOrElse(path, immutable.IndexedSeq(elm))
    }
  38. abstract def withChildSeqs(newChildSeqs: IndexedSeq[IndexedSeq[ThisNode]]): ThisElem

    Permalink

    Shorthand for withChildren(newChildSeqs.flatten)

  39. abstract def withChildren(newChildren: IndexedSeq[ThisNode]): ThisElem

    Permalink

    Returns an element with the same name, attributes and scope as this element, but with the given child nodes

  40. abstract def withPatchedChildren(from: Int, newChildren: IndexedSeq[ThisNode], replace: Int): ThisElem

    Permalink

    Shorthand for withChildren(children.patch(from, newChildren, replace))

  41. abstract def withUpdatedChildren(index: Int, newChild: ThisNode): ThisElem

    Permalink

    Shorthand for withChildren(children.updated(index, newChild))

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from IsNavigableApi

Inherited from AnyElemNodeApi

Inherited from AnyElemApi

Inherited from AnyRef

Inherited from Any

Ungrouped