title: How to return a list of lists from a recursive function in scala?
body: <p>I am creating a function that must return a List of Lists. So The function takes a List as its argument and it then does some calculations involving the data in this list. What the function does to the list is irrelevant to solving my problem, however the function calls itself on data in the list, modifying it slightly. What I need to do, is when the base case is reached, I need every variation of the list that has made it to the base case to then be added to the list to be returned. </p>
  
  <p>The structure of the function is as follows:</p>
  
  <pre><code>def foo(last: List[Int]) : List[List[Int]] = {
    if(condition){
      *return the List[List[Int]]
    }
    else{
      lst.foreach(x =&gt; foo(x :: lst))
    }
  }
  </code></pre>