This is a sample scala code-
def foo(n : Int, ls : List[Int]) : Int =
ls match {
case Nil => n
case hd :: tl => hd*foo(n-1,tl)
}
If I pass foo(7,List(1,2,-2,2)) gives me -24 But I don't understand how this works, can anyone help me understand how the recursion works here?