Skip to content

[Feature] Add signal operators for Flow<Boolean> #4673

Description

@g000sha256

What are you trying to do?

React to one side of a Flow<Boolean> toggle - hide a spinner when isLoading becomes false, navigate when isAuthenticated becomes true. The boolean itself is redundant by then; only the fact of occurrence matters.

What problem does this actually solve?

Deriving an event stream from Flow<Boolean> today splits intent across multiple steps and produces a misleading intermediate type (a stream always carrying the same constant). No concise, type-honest way to say "this is now an event stream".

Your idea (optional)

Proposed signature

fun Flow<Boolean>.filterTrue(): Flow<Unit>
fun Flow<Boolean>.filterFalse(): Flow<Unit>

or

fun Flow<Boolean>.filterIsTrue(): Flow<Unit>
fun Flow<Boolean>.filterIsFalse(): Flow<Unit>

Example

isAuthenticated // Flow<Boolean>
    .filterTrue() // or filterIsTrue
    .collect { showProtectedScreen() }

Prior art or similar ideas (optional)

No response

Anything else? (optional)

The same "Boolean signal" framing extends naturally to terminal counterparts - mentioned as direction, not as part of this request:

suspend fun Flow<Boolean>.firstTrue(): Unit
suspend fun Flow<Boolean>.firstFalse(): Unit

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