title: How to embed if statement inside a map
body: <p>I have a definition calculation cosine similarity for each combination coming from a matrix. However, I want the definition runs under some certain conditions.</p>
  
  <p>The definition is given below:</p>
  
  <pre><code>def neighbours(signatures: Iterable[Signature], minCosineSimilarity: Double): Iterator[MatrixEntry] = {
     signatures.
        toSeq.
        sortBy(_.index). // sort in order to create an upper triangular matrix
        combinations(2)
        .map {
          case first :: other :: nil =&gt;
          if((first.index &lt; 4 &amp;&amp; other.index &gt; 3) || (first.index &gt; 3 &amp;&amp; other.index &lt; 4)){}
          val cosine = Cosine(first.vector, other.vector)
          MatrixEntry(first.index, other.index, cosine)
      }.
        filter(_.value &gt;= minCosineSimilarity)
    }
  </code></pre>
  
  <p>It calculates cosine similarity for a given pair coming from "combinations(2)" line. I have added a line containing if statement. How can I make this if condition valid here? </p>