nwh
Flow
chunked
List
fun <T> Flow<T>.chunked(size: Int) = flow { val list = mutableListOf<T>() collect { list.add(it) if (list.size == size) { emit(list.toList()) list.clear() } } if (list.isNotEmpty()) emit(list) }
louiscad
fun <T> Flow<T>.chunked(size: Int): Flow<List<T>> = flow { val list = mutableListOf<T>() collect { list.add(it) if (list.size == size) { emit(list.toList()) list.clear() } } if (list.isNotEmpty()) emit(list) }
A modern programming language that makes developers happier.