In functional programming, we often look at a list in terms of its head (first-element) and tail (rest-of-list). This allows us to define operations on a list recursively. For example, how do we sum a list of integers such as [1, 2, 3, 4]? def sum(l : List[Int]): Int =…