title: Checking whether an Array[A] is sorted?
body: <p>While working through a problem found in 'Functional Programming in Scala':</p>
  
  <blockquote>
    <p>Implement isSorted, which checks whether an Array[A] is sorted according to a given comparison function: </p>
  </blockquote>
  
  <pre><code>def isSorted[A](as: Array[A], ordered: (A,A) =&gt; Boolean): Boolean
  </code></pre>
  
  <p>While comparing my answer to the below solution provided by the author(s):</p>
  
  <pre><code>  // Exercise 2: Implement a polymorphic function to check whether
    // an `Array[A]` is sorted
    def isSorted[A](as: Array[A], gt: (A,A) =&gt; Boolean): Boolean = {
      @annotation.tailrec
      def go(n: Int): Boolean =
        if (n &gt;= as.length-1) true
        else if (gt(as(n), as(n+1))) false
        else go(n+1)
  
      go(0)
    }
  </code></pre>
  
  <p>I am getting confused by the following line of code: <code>else if (gt(as(n), as(n+1))) false</code></p>
  
  <p>I thought when using a function as a parameter in Scala, one would need to actually define a separate function outside the scope of the current function (i.e. have another function defined that does what <code>gt</code> would need to do)? I don't see <code>gt</code> defined anywhere else, so how is it able to provide a <code>Boolean</code> value to use  in <code>isSorted</code>?</p>
  
  <p>Are my assumptions correct, or am I completely something missing here with using functions as parameters? A detailed explanation is much appreciated.</p>