mapToSingle

fun <T> KQLiteCursor.mapToSingle(mapper: (KQLiteCursor) -> T): T

Maps the first row of this KQLiteCursor into a single object of type T using mapper.

This is a terminal operation that expects exactly one row in the result set.

Cursor lifecycle

  • The KQLiteCursor is automatically closed after execution, regardless of whether an exception is thrown.

  • This uses use to ensure resource safety.

Characteristics

Return

The single mapped element of type T.

Author

MOHAMMAD AZIM ANSARI

Parameters

mapper

Transforms the cursor row into T.

See also

Throws

if the cursor is empty.

if the cursor has more than one row.


fun <T> Flow<KQLiteCursor>.mapToSingle(dispatcher: CoroutineDispatcher? = null, mapper: (KQLiteCursor) -> T): Flow<T>

Maps each emitted KQLiteCursor from the upstream Flow into a single object of type T.

Each cursor emission is expected to contain exactly one row. The cursor is fully consumed and automatically closed after reading one row.

Cursor lifecycle

  • The KQLiteCursor is automatically closed after execution, regardless of whether an exception is thrown.

  • This uses use to ensure resource safety.

Threading

  • Mapping is executed on Dispatchers.IO by default.

  • A custom dispatcher can be provided to control threading.

  • Uses flowOn to shift upstream execution.

Characteristics

Return

A flow emitting a single object of type T for each cursor emission.

Author

MOHAMMAD AZIM ANSARI

Parameters

dispatcher

Optional CoroutineDispatcher for upstream execution (defaults to Dispatchers.IO).

mapper

Transforms the single cursor row into T.

See also