title: How to get the current and next element of List of list of options in scala
body: <p>This question might be duplicated, however, I've not come across any question that answers my problem.</p>
  
  <p>So I have a <code>List[ List[ Option[ Double ] ] ]</code></p>
  
  <p>With the following data:</p>
  
  <pre class="lang-scala prettyprint-override"><code>var tests = List(
    List(Some(313.062468), Some(27.847252)),
    List(Some(301.873641), Some(42.884065)),
    List(Some(332.373186), Some(53.509768))
  )
  </code></pre>
  
  <p>I'd like to calculate this equation:</p>
  
  <pre class="lang-scala prettyprint-override"><code>def findDifference(oldPrice: Option[Double], newPrice: Option[Double]): Option[Double] = {
      return Some(( newPrice.get - oldPrice.get ) / oldPrice.get)
  }
  </code></pre>
  
  <p>on the following:</p>
  
  <p>It's doing the calculation on the element of two lists:</p>
  
  <p><code>(Some(301.062468) - Some(313.062468)) / Some(313.062468)</code></p>
  
  <p><code>(Some(332.373186) - Some(301.873641)) / Some(301.873641)</code></p>
  
  <p><code>(Some(42.884065) - Some(27.847252)) / Some(27.847252)</code></p>
  
  <p><code>(Some(53.509768) - Some(42.884065)) / Some(42.884065)</code></p>
  
  <p>The result should return:
  #</p>
  
  <pre class="lang-scala prettyprint-override"><code>List(
    List(Some(-0.03573991820699504), Some(0.5399747522663995))
    List(Some(0.10103414428290529), Some(0.24777742035415723))
  )
  </code></pre>
  
  <h1>My code so far</h1>
  
  
  
  <pre class="lang-scala prettyprint-override"><code>def findDifference(oldPrice: Option[Double], newPrice: Option[Double]): Option[Double] = {
      return Some(( newPrice.get - oldPrice.get ) / oldPrice.get)
  }
  
  def get_deltas(data: List[List[Option[Double]]]):  List[List[Option[Double]]] = {
    for {
      i &lt;- data
      // So this is where I am stuck. I have the current element i, but I need the same index element in the next list
    } ( findDifference(i,?) }
  </code></pre>
  
  <h1>My output If I print my I in For-comprehension</h1>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>List(Some(313.062468), Some(27.847252))
  List(Some(301.873641), Some(42.884065))
  List(Some(332.373186), Some(53.509768))</code></pre>
  </div>
  </div>
  </p>
  
  <h1>Where Am I stuck?</h1>
  
  <p>I'm stuck in the fact that I don't know how to get the element of the same index in the list 1 from List 2 and List 3 and do the necessary calculation?</p>
  
  <p>Please help me achieve my result output </p>