title: How do I pass an anonymous function to map()?
body: <p>I'm working through a little code challenge in Kotlin.</p>
  <blockquote>
  <p>Write a function that nests the elements of a list one level deeper by repeating that
  element inside a new list a given number of times.
  Examples</p>
  </blockquote>
  <blockquote>
  <p>(nest [:a :b :c] 2) ;=&gt; ((:a :a) (:b :b) (:c :c))</p>
  </blockquote>
  <blockquote>
  <p>(nest [] 10) ;=&gt; ()</p>
  </blockquote>
  <blockquote>
  <p>(nest [1 2 3 4] 1) ;=&gt; ((1) (2) (3) (4))</p>
  </blockquote>
  <blockquote>
  <p>(nest [1 2 3] 0) ;=&gt; (()()())</p>
  </blockquote>
  <p>I implemented <code>nest</code> like so:</p>
  <pre><code>fun &lt;R&gt; nest(list: List&lt;R&gt;, repeat: Int) =
      list.map{
          mem -&gt; generateSequence(1) { it }
                  .map { mem }
                  .take(repeat)
                  .toList()
      }
  </code></pre>
  <p>However, I'm wondering how I'd write the lambda as a separate anonymous function, which I'd pass to <code>map</code>, like...</p>
  <pre><code>val anonFunction = ???
  list.map(anonFunction)
  </code></pre>
  <p>I'm not sure how this would work syntactically.</p>