title: Filter nested list with kotlin
body: <p><strong>Ques:</strong> I want to filter list within a list. All of my data models are immutable. </p>
  
  <p>My JSON structure looks like this </p>
  
  <pre><code>{
    "root": [
      {
        "id": 2,
        "val": 1231.12,
        "fruit": [
          {
            "id": 2,
            "name": "apple"
          }
        ]
      },
      {
        "id": 3,
        "val": 1231.12,
        "fruit": [
          {
            "id": 2,
            "name": "apple"
          },
          {
            "id": 3,
            "name": "orange"
          }
        ]
      }
    ],
    "fruits": [
      {
        "id": 1,
        "name": "apple"
      },
      {
        "id": 2,
        "name": "guava"
      },
      {
        "id": 3,
        "name": "banana"
      }
    ]
  }
  </code></pre>
  
  <p><strong>Problem Statement</strong> - Basically, I want to create a list of all items of root where fruit name is apple. Currently, my naive solution looks like this. This involves creating a temporary mutuable list and then add specific items to it.</p>
  
  <p>Below solution works fine but is there any other better way to achieve the same.</p>
  
  <pre><code>val tempList = arrayListOf&lt;RootItem&gt;()
  
  root?.forEach { item -&gt; 
      item.fruit.filter {
          // filter condition
          it.id != null &amp;&amp; it.name == "apple"
      }
      testList.add(item)
  }
  </code></pre>