Skip to content

Commit 361d02e

Browse files
committed
Improve combineAdjacentTextNodes logic
Remove lastOption and Option matching in favor of a more elegant foldRight solution proposed by ashawley.
1 parent 1e3b288 commit 361d02e

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

shared/src/main/scala/scala/xml/Utility.scala

+3-7
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ object Utility extends AnyRef with parsing.TokenTests {
5151
}
5252

5353
private def combineAdjacentTextNodes(children: Node*): Seq[Node] = {
54-
children.foldLeft(Seq.empty[Node]) { (acc, n) =>
55-
(acc.lastOption, n) match {
56-
case (Some(Text(l)), Text(r)) => {
57-
acc.dropRight(1) :+ Text(l + r)
58-
}
59-
case _ => acc :+ n
60-
}
54+
children.foldRight(Seq.empty[Node]) {
55+
case (Text(left), Text(right) +: accMinusLast) => Text(left + right) +: accMinusLast
56+
case (n, acc) => n +: acc
6157
}
6258
}
6359

0 commit comments

Comments
 (0)