val sumOfElements = new Summary[Int, Int] {
def empty = 0
def combine(a: Int, b: Int) = a + b
def apply(value: Int) = value
}
val sum = PersistentSummary.vector(sumOfElements)
val xs = Vector(0 until 10000: _*)
println(sum(xs))
// update an element. Most of the underlying tree of set will be reused
val xs1 = xs.updated(5000, 20000)
// will reuse most node summaries from last call
println(sum(xs1))
Calculating the sum of the updated collection xs1 will be very quick, because the tree structure of xs (for which we already know the summaries for each node) is mostly reused in xs1.