title: Kotlin: Passing operator as a function parameter
body: <p>I've the following function in Kotlin</p>
  
  <pre><code>fun evaluate(first:Int?, second:Int?) {
      var result = 0
      if (v.equals('*')) {
          result = (first ?: 0) * (second ?: 0)
      } else if (v.equals('+')) {
          result = (first ?: 0) + (second ?: 0)
      } else if (v.equals('-')) {
          result = (first ?: 0) - (second ?: 0)
      } else if (v.equals('/')) {
          result = (first ?: 0) / (second ?: 0)
      }
      return result   
  }
  </code></pre>
  
  <p>I want to change it in a way so that I can pass as a third parameter needed operator and evalute the expression. Something like</p>
  
  <pre><code>fun evaluate(first:Int?, second:Int?, op: () -&gt; Unit):Int {
      return (first ?: 0).op(second ?: 0)
  }
  </code></pre>
  
  <p>How can I pass the operator as a function in this case? I checked the same kind of a <a href="https://stackoverflow.com/questions/16120697/kotlin-how-to-pass-a-function-as-parameter-to-another">question</a>, but it is not clear how you can do that with operator.</p>