Question: in wpf, I have a canvas, that when double-clicked, needs to be opened in a separate tab for editing. when switching tabs, I need to be able to see the canvas in its original place, with the changes applied.
Is there a trick to make it the child of both TabItems? if no, is there anything else I can do?
Thanks!

Answer: 
Just zip your stream with a shifted version of itself and sum the two elements.

```
val s1 = Stream.from(0) // 0, 1, 2, 3, ...
val s2 = Stream.from(1) // 1, 2, 3, 4, ...
val sumOfTwo = s1.zip(s2).map{ case (a,b) => a+b } // 1, 3, 5, 7, ...

```

To compute the total sum, just use the scan function that acts like a fold but returning elements at each step.

```
val totalSum = s1.scan(0)((ctr, el) => ctr + el) // 0, 1, 3, 6, 10, ...

```
[This answer](https://stackoverflow.com/a/8567134/1071311) computes the cumulative sum by using a variable for the accumulated result instead of `scan()`. Example program: 

```
import scala.collection.immutable.Stream

object Main extends App {
    // 1, 2, 3, ...
    val naturals = Stream.from(1) 

    // cumulative sum (see https://stackoverflow.com/a/8567134/1071311)
    def sumUp(s : Stream[Int], acc : Int = 0) : Stream[Int] =
        Stream.cons(s.head + acc, sumUp(s.tail, s.head + acc))

    val firstFive = sumUp(naturals, 0).take(5)

    firstFive.foreach(println _)
}

```

Output:

```
1
3
6
10
15

```