Created
December 7, 2022 18:25
-
-
Save LouisCAD/3ff868c8cb1ee1ff4bd855b11ea65715 to your computer and use it in GitHub Desktop.
Revisions
-
LouisCAD created this gist
Dec 7, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import kotlinx.coroutines.* import kotlinx.coroutines.channels.* import kotlinx.coroutines.flow.* fun <T> Flow<T>.chunked(size: Int): Flow<List<T>> = flow { val elements = ArrayList<T>(size) collect { elements.add(it) if (elements.size == size) { emit(elements.toList()) elements.clear() } } if (elements.isNotEmpty()) emit(elements) }