Skip to content

short circuiting reductions in flows #2183

@jeffzoch

Description

@jeffzoch

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions