title: scala Range for Long
body: <p>I'm new to the Scala language.</p>
  
  <p>I need Range for Long type.</p>
  
  <p>I need a List of [1, 2, 3 ... 10000000] with step 1. If I use until/to I get an error because of using Long instead of Int.</p>
  
  <p>I try to write simple function which expects a start, an end and and an empty List and generates a List of [start .. end].</p>
  
  <p>Here is my function:</p>
  
  <pre><code>def range_l(start : Long, end : Long, list : List[Long]) : List[Long] = {
      if (start == end){
          val add_to_list = start :: list
          return add_to_list
      }
      else {
          val add_to_list = start :: list
          range_l(start + 1, end, add_to_list)
      }
  }
  </code></pre>
  
  <p>If I call it like: <code>range_l(1L, 1000000L, List())</code> i get <code>OutOfMemory</code> error in the following line: <code>add_to_list = start :: list</code></p>
  
  <p>What can you advice me? How can I get <code>Range[Long]</code> or how can I optimize the function. How can I avoid OutOfMemory?</p>
  
  <p>Thank you.</p>