Question: How does one map each item in a list iteratively with it's remaining tail? Pseudo code example:

```
val list = List(1,2,3,4) 
list.foreach((head, tail) => println(s"head= $head, tail= $tail")) 
// head= 1, tail = List(2, 3, 4) 
// head= 2, tail = List(3, 4) 
// head= 3, tail = List(4) 
// head= 4, tail = List()

```

Answer: 
```
def rec(l: List[Int]) : Unit = {
    l match {
        case head::tail => println(s"head= $head, tail= $tail")
            rec(tail)
        case _ =>
    }
}

scala> rec(l)
    head= 1, tail= List(2, 3, 4)
    head= 2, tail= List(3, 4)
    head= 3, tail= List(4)
    head= 4, tail= List()

```
A (to me) more straightforward answer. As @LuisMiguelMejíaSuárez says, tails is your friend

```
(xs zip xs.tails.toList) map {case (h, t) => println("Head: " + h + " Tail: " + t)}

```

The .toList is a pity, though

---