jw
01/22/2018, 9:51 PMsuspend fun sum(): Long
inside which I have a reference to something with the method suspend fun consume(consumer: suspend (Long) -> Unit)
. The implementation is the obvious thing:
var sum = 0L
numbers.consume { sum += it }
return sum
Now let's say I want to specify a maximum number of numbers. How can I cause the numbers.consume
to stop pushing numbers at me once that max is hit?elizarov
01/23/2018, 8:02 AMconsumer
signature, e.g. define it as consumer: suspend (Long) -> Boolean
where the resulting boolean indicates whether consumer is ready to accept more.