combine

fun <T, R> List<Result<T>>.combine(transform: (List<T>) -> R): Result<R>

Combines multiple Results into a single Result containing a list of values.

This function uses an "all-or-nothing" strategy: if any Result in the list is a failure, the entire operation fails. This is implemented by using getOrThrow() which will throw the first encountered exception, causing runCatching to wrap it in a Result.failure.

For partial success scenarios, use mapNotNull or filter instead.

Return

Result containing the transformed value, or failure if any input Result failed

Parameters

transform

Function to transform the list of values