title: Scala Implicit conversion for Lambdas
body: <p>I am trying to understand the implicit function types from the link - <a href="http://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html" rel="nofollow noreferrer">http://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html</a> and below is a sample code as example. In the below code we first create a class Transaction.</p>
  
  <pre><code>class Transaction {
    private val log = scala.collection.mutable.ListBuffer.empty[String]
    def println(s: String): Unit = log += s
  
    private var aborted = false
    private var committed = false
  
    def abort(): Unit = { aborted = true }
    def isAborted = aborted
  
    def commit(): Unit =
    if (!aborted &amp;&amp; !committed) {
       Console.println("******* log ********")
       log.foreach(Console.println)
       committed = true
    }
  }
  </code></pre>
  
  <p>Next I define two methods f1 and f2 as shown below</p>
  
  <pre><code>def f1(x: Int)(implicit thisTransaction: Transaction): Int = {
    thisTransaction.println(s"first step: $x")
    f2(x + 1)
  }
  def f2(x: Int)(implicit thisTransaction: Transaction): Int = {
    thisTransaction.println(s"second step: $x")
    x
  }
  </code></pre>
  
  <p>Then a method is defined to invoke the functions</p>
  
  <pre><code>def transaction[T](op: Transaction =&gt; T) = {
    val trans: Transaction = new Transaction
    op(trans)
    trans.commit()
  }
  </code></pre>
  
  <p>Below lambda is used to invoke the code</p>
  
  <pre><code>transaction {
      implicit thisTransaction =&gt;
        val res = f1(3)
        println(if (thisTransaction.isAborted) "aborted" else s"result: $res")
  }  
  </code></pre>
  
  <p>My question is if I change the <code>val trans: Transaction = new Transaction</code> to <code>implicit val thisTransaction = new Transaction</code> and change <code>op(trans)</code> to <code>op</code> it is not working. </p>
  
  <p>I am not able to understand why even if thisTransaction of type Transaction is present in the scope it is not being used?</p>