title: Kotlin - Modify nested Data (Add item to List in an Object in another List in an Object)
body: <p>My User object has a <code>List&lt;Post&gt;</code>, each Post has a <code>List&lt;Tag&gt;</code>.
  Now I would like to add a Tag item to the <code>List&lt;Tag&gt;</code>.</p>
  <p>User:</p>
  <pre><code>data class User(
      val id: String,
      val name: String,
      val posts: List&lt;Post&gt; = listOf()
  )
  </code></pre>
  <p>Post:</p>
  <pre><code>data class Post(
      val id: Int,
      val name: String
      val tags: List&lt;Tags&gt; = listOf()
  ) 
  </code></pre>
  <p>Now I would like to update my MutableStateFlow containing the User object:</p>
  <pre><code>private val _userStateFlow: MutableStateFlow&lt;User?&gt; = MutableStateFlow(User())
  val userStateFlow: StateFlow&lt;User?&gt; = _userStateFlow
  </code></pre>
  <p>To find the correct Post (containing the <code>List&lt;Tag&gt;</code> I want to update) I have the id of it (passedPostId)</p>
  <pre><code>val postsList = userStateFlow.value?.posts!!.toMutableList()
  val tagsList = postsList.find { it.id == passedPostId }?.tags?.toMutableList()
  tagsList.add(Tag(&quot;test&quot;))
  </code></pre>
  <p>Now I got an updated tagsList but I need an updated postsList to pass it to my MutableStateFlow.
  I am not sure how to do it.
  This is how I update my MutableStateFlow:</p>
  <pre><code>_userStateFlow.update { it?.copy(posts = newPosts)
  </code></pre>
  <p>If I have the index of the post I want to update everything works fine, but In my Case I only can call .find because all i have is the id of the post.</p>
  <pre><code>val posts = userStateFlow.value?.posts!!.toMutableList()
  posts[index] = posts[index].copy(tags = posts[index].tags.plus(Tag(&quot;test&quot;)
  userStateFlow.value = userStateFlow.value?.copy(posts = posts)
  </code></pre>