fold

inline fun <R> fold(onSuccess: (T) -> R, onFailure: (BleException) -> R): R

Folds the result into a single value by applying the appropriate function.

val message: String = result.fold(
onSuccess = { data -> "Received ${data.size} bytes" },
onFailure = { error -> "Error: ${error.message}" }
)

Return

The result of applying the appropriate function.

Parameters

onSuccess

The function to apply if this is a success.

onFailure

The function to apply if this is a failure.