title: How can I find the minimum with binary search on an interval in Scala?
body: <p>Okay so im trying to find the minimum of an given interval with binary search in Scala, but the minimum has to match a also given function. 
  Heres my code:</p>
  
  <pre><code>def binarySearch: (Int =&gt; Boolean) =&gt; (Int, Int) =&gt; Int = f =&gt; (l, h) =&gt; {
    def bs: ((Int =&gt; Boolean) =&gt; (Int, Int, Int) =&gt; Int) = f =&gt; (l, h, minimum) =&gt; {
  
      val mid = l + ((h-l) / 2)
  
      mid match{
        case mid if(f(mid) == false) =&gt; bs(f)(mid+1, h, mid)
        case mid if(f(mid) == true &amp;&amp; mid &gt; minimum) =&gt; bs(f)(l, mid-1, minimum)
        case mid if(f(mid) == true &amp;&amp; mid &lt; minimum) =&gt; bs(f)(mid+1, h, mid)
        case mid =&gt; mid
      }
    }
    bs(f)(l, h, 0)
  }
  </code></pre>
  
  <p>I think my problem is, that i´m not correctly saving the minimum.</p>
  
  <p>A testcase could look like this:</p>
  
  <pre><code>val v = Vector(0, 1, 2, 3, 7, 9)
  binarySearch(v(_) &lt; 5)(0, v.length) == 4
  </code></pre>
  
  <p>Any ideas?</p>