title: maxByOrNull function in Kotlin
body: <p>Nowadays I am learning Kotlin and I have a question. In the below code, I did not understand the work done in line 2 and 3. Actually I understood the work done but the code seemed a little complicated to me. Can you explain the code in these lines?</p>
  <pre><code>data class Item(val name: String, val price: Float)                                         // 1  
  
  data class Order(val items: Collection&lt;Item&gt;)  
  
  fun Order.maxPricedItemValue(): Float = this.items.maxByOrNull { it.price }?.price ?: 0F    // 2  
  fun Order.maxPricedItemName() = this.items.maxByOrNull { it.price }?.name ?: &quot;NO_PRODUCTS&quot;  // 3
  
  val Order.commaDelimitedItemNames: String                                                   // 4
      get() = items.map { it.name }.joinToString()
  
  fun main() {
  
      val order = Order(listOf(Item(&quot;Bread&quot;, 25.0F), Item(&quot;Wine&quot;, 29.0F), Item(&quot;Water&quot;, 12.0F)))
      
      println(&quot;Max priced item name: ${order.maxPricedItemName()}&quot;)                           // 5
      println(&quot;Max priced item value: ${order.maxPricedItemValue()}&quot;)
      println(&quot;Items: ${order.commaDelimitedItemNames}&quot;)                                      // 6
  
  }
  </code></pre>
  <p>I would be very happy if you can help. Thanks!</p>