-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
I have a use case where I have a series of data points coming in over the network and I want to reduce them to a single value.
So i do something like:
fun compute() {
getValues()
.map{}
.onEach{}
.reduce { res: Set<V>, curr: Set<V> -> res.intersection(curr) //I dont actually use intersection but a slightly different method that handles empty sets.
}What I'd like to do is short-circuit this reduction if the empty set is ever passed in. Some of the data points from getValues() may come in a minute after the first data point. If the first data point was the empty set {} then we ended up waiting for no reason.
Is there a simple mechanism to do this sort of short-circuiting in a general fashion without resorting to throwing exceptions in the reduction?