June 2018
Intermediate to advanced
310 pages
6h 32m
English
It's very common to see this chunking logic in production code.
You have a huge list of identifiers that you read from somewhere and you need to check whether your database or some remote service contains them. But there are limitations on how many identifiers you can pass with a single request. Databases, for example, often have limitations of the number of arguments to a query and on the total query length:
fun dbCall(ids: List<Int>) { if (ids.size > 1000) { throw RuntimeException("Can't process more than 1000 ids") }
// Does something here}
We can't simply pass an entire list to our function:
// That will fail at runtimedbCall(hugeList)
So, we write large piles of imperative code:
val pageSize = 1000val pages = hugeList.size ...
Read now
Unlock full access