title: Is there a less ugly way to return function in Kotlin?
body: <p>This declaration works, but is not the most beautiful code. Is there a way to return functions less ugly? I tried <code>(s: String) -&gt; writer.println(s)</code> but this didn't work.</p>
  
  <pre><code>val writeStuff: (PrintWriter) -&gt; (String) -&gt; Unit = {
      val writer = it
      val f: (String) -&gt; Unit = {
          writer.println(it)
      }
      f
  }
  PrintWriter("test").use { writeStuff(it)("TEST") }
  </code></pre>
  
  <p>EDIT: a bit more concrete example:</p>
  
  <pre><code>val writeStuff: (PrintWriter) -&gt; (String) -&gt; Unit = { writer -&gt;
      { writer.println(it) }
  }
  
  val sendStuff: (Any) -&gt; (String) -&gt; Unit = { sender -&gt;
      { sender.equals(it) }
  }
  
  @Test fun test1() {
      val li = listOf("a", "b", "c")
  
      val process: List&lt;(String) -&gt; Unit&gt; = 
          listOf(writeStuff(PrintWriter("a")), sendStuff(Object()))
  
      process.map { li.map(it) }
  }
  </code></pre>