How is putting the lambda expression after the parameters on a mapTo call legal syntax? : <p>I found a piece of code I do not understand. </p>

<p>I am transforming a <code>JSONArray</code> into a <code>List</code>.<br>
Kotlin provides the function <code>mapTo</code> in it's <code>stdlib</code>(<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-to.html" rel="noreferrer">link</a>)</p>

<blockquote>
  <p><strong>mapTo</strong></p>

<pre><code>inline fun &lt;T, R, C : MutableCollection&lt;in R&gt;&gt; Iterable&lt;T&gt;.mapTo(
    destination: C, 
    transform: (T) -&gt; R
): C (source)
</code></pre>
  
  <p>Applies the given transform function to each element of the original collection and appends the results to the given destination.</p>
</blockquote>

<p>This functions has 2 parameters and can be used like this (as expected):</p>

<pre><code>(0..jsonArray.length() - 1).mapTo(targetList, {it -&gt; jsonArray[it].toString()})
</code></pre>

<p>But apparently this is also valid syntax (not expected):</p>

<pre><code>(0..jsonArray.length()-1).mapTo(targetList) {it -&gt; jsonArray[it].toString()}
</code></pre>

<p>As you can see, the function parameters end after <code>outputList</code> and the lambda expression is just put at the end of the function call.</p>

<hr>

<p>Furthermore this is legal (as expected):</p>

<pre><code>val transformation = {it : Int -&gt; jsonArray[it].toString()}
(0..jsonArray.length()-1).mapTo(targetList, transformation)
</code></pre>

<p>but this is not (???):</p>

<pre><code>val transformation = {it : Int -&gt; jsonArray[it].toString()}
(0..jsonArray.length()-1).mapTo(targetList) transformation
</code></pre>
