https://kotlinlang.org logo
Title
b

breandan

01/26/2021, 6:52 AM
Is there an equivalent Flow construct for the sequence predicates
any
and
all
? I need a way to short circuit a Flow if a value is ever found matching a predicate, similar to `anyMatch`/`allMatch`/`noneMatch` in the Java Streams API
This is the closest thing I found, but it seems like there should be a simpler way:
.firstOrNull { ... } != null
m

Mattias Flodin

01/26/2021, 7:35 AM
takeWhile?
(to replace any)
And all would just be a typical collect where you reduce the values, yeah?
actually you have reduce() already
b

breandan

01/26/2021, 9:06 AM
reduce
wouldn’t work since it doesn’t short circuit. I guess
takeWhile
works, but it’s the same problem as
firstOrNull
since I don’t need the values themselves, just the Boolean
m

Mattias Flodin

01/26/2021, 1:01 PM
right