title: Write a function that has the same default values as a constructor
body: <p><strong>Abstract problem</strong>:</p>
  <p>Consider the following:</p>
  <pre><code>data class Data(val i: Int, val s: String = &quot;&quot;)
  
  fun &lt;A1, A2, D&gt; make(ctor: KFunction2&lt;A1, A2, D&gt;, sideEffect: (D) -&gt; D) =
      { a1: A1, a2: A2 -&gt; sideEffect(ctor(a1, a2)) }
  
  val makeData = make(::Data) {
      it.also { println(&quot;Side effect: i=${it.i}, s=${it.s}&quot;) }
  }
   
  </code></pre>
  <p>I can call makeData with all of the constructor arguments to obtain
  an instance of <code>Data</code> and also call some side-effect. However, I
  cannot omit parameters and use the constructor's default values instead:</p>
  <pre><code>val d1 = makeData(42, &quot;hi&quot;)
  val d2 = makeData2(42) // Error: No value passed for parameter 'p2'
  </code></pre>
  <p>How can I rewrite the generic <code>make</code> such that its output is a function with default values?</p>
  <p><strong>What I'm trying to achieve</strong>:</p>
  <p>With Kotlin React, I declare properties like so:</p>
  <pre><code>external interface VideoListProps: RProps { var videos: List&lt;Video&gt; }
  </code></pre>
  <p>To use the component within render(), I can write:</p>
  <pre><code>child(VideoList::class) { attrs.videos = unwatchedVideos }
  </code></pre>
  <p>I don't like this for three reasons: (a) using a component is much more verbose than compared to TypeScript/TSX,
  (b) properties need to be declared as var while they should be read-only (val), (c) there is no enforcement that a member is actually declared; <code>props.videos</code> may end up as <code>null</code> at runtime even though the Props interface does not declare it as nullable.</p>
  <p>The tutorial for Kotlin React suggests to use lambdas with receivers like so:</p>
  <pre><code>fun RBuilder.videoList(handler: VideoListProps.() -&gt; Unit): ReactElement {
      return child(VideoList::class) {
          this.attrs(handler)
      }
  }
  </code></pre>
  <p>Now I can use the component like so:</p>
  <pre><code>videoList { videos = unwatchedVideos }
  </code></pre>
  <p>While the calling site now looks much more concise, I now have to copy/paste and adapt the lambda snippet for each and every component I write. This is much more verbose than in TypeScript, where I don't need this construct. Moreover, the videoList lambda has no access to other members of the RBuilder as <code>this</code> now points to RProps. So if I need to define a React <code>key</code>, I'm at a loss and need to use the child(...) syntax from before. And lastly, the problem (c) from above still exists.</p>
  <p>To make this better, I wrote the following helper constructs:</p>
  <pre><code>fun &lt;P : RProps, A1&gt; RBuilder.childWithProps(
      klass: KClass&lt;out Component&lt;P, *&gt;&gt;,
      ctor: KFunction1&lt;A1, P&gt;
  ) =
      { a1: A1, handler: RHandler&lt;P&gt; -&gt; child(klass.rClass, ctor(a1), handler) }
  
  fun &lt;P : RProps, A1, A2&gt; RBuilder.childWithProps(
      klass: KClass&lt;out Component&lt;P, *&gt;&gt;,
      ctor: KFunction2&lt;A1, A2, P&gt;
  ) =
      { a1: A1, a2: A2, handler: RHandler&lt;P&gt; -&gt; child(klass.rClass, ctor(a1, a2), handler) }
  
  // more for KFunction3, KFunction4, ... up to a reasonable amount of members, e.g. 16
  </code></pre>
  <p>I admit this is also kind of ugly, but I need to write this once only. Now I can declare props like this (note the val instead of var):</p>
  <pre><code>data class VideoListProps(val videos: List&lt;Videos&gt;) : RProps
  </code></pre>
  <p>The additional code for each component is now much more concise:</p>
  <pre><code>val RBuilder.videoList get() = childWithProps(VideoList::class, ::VideoListProps) 
  </code></pre>
  <p>And use it like this:</p>
  <pre><code>videoList(watchedVideos) { /* you can set React key or children here if needed */ }   
  </code></pre>
  <p>Kotlin now marks it as an error if I forget to set all properties.
  Everything now looks concise, I write even slightly less code than in TypeScript/TSX. The only remaining problem is that now I always have to pass all members, since any default values of the data constructor will still be madatory in the wrapper. <strong>This is the actual question.</strong></p>