---
title: "Comment by Ilya on \"Leveraging fold operator in Kotlin flow to optimize Room DB upserts\" | Hashnode"
description: "Why wouldn't you just use subList? db.chatDao().insertChats(list.subList(0, 45)) if (list.size &gt; 45) list.subList(45, list.size).chunked(150).forEach { db.ch"
url: "https://hashnode.com/posts/leveraging-fold-operator-in-kotlin-flow-to-optimize-room-db-upserts/655c44afe10e32209234a4f1/comment/686eae2a3c049ed70a8ca99d"
---

[Discussion](https://hashnode.com/posts/leveraging-fold-operator-in-kotlin-flow-to-optimize-room-db-upserts/655c44afe10e32209234a4f1)

Comment [Leveraging fold operator in Kotlin flow to optimize Room DB upserts](https://hashnode.com/posts/leveraging-fold-operator-in-kotlin-flow-to-optimize-room-db-upserts/655c44afe10e32209234a4f1)

[Ilya](https://hashnode.com/@Snowmaze)

[Jul 9, 2025](https://hashnode.com/posts/leveraging-fold-operator-in-kotlin-flow-to-optimize-room-db-upserts/655c44afe10e32209234a4f1/comment/686eae2a3c049ed70a8ca99d)

Why wouldn't you just use subList? db.chatDao().insertChats(list.subList(0, 45))

if (list.size > 45) list.subList(45, list.size).chunked(150).forEach { db.chatDao().insertChats(it) }

[Tushar Pingale](https://hashnode.com/@tusharpingale04)

[Nov 30, 2025](https://hashnode.com/posts/leveraging-fold-operator-in-kotlin-flow-to-optimize-room-db-upserts/655c44afe10e32209234a4f1/comment/686eae2a3c049ed70a8ca99d#reply-692c37f4d5a60d94966e73b9)

This is because we are unaware of the list size. The list is populated based on paginated response.
