fold

fun <R, T> DecodingResult<T>.fold(onSuccess: (value: T) -> R, onFailure: (exception: Throwable) -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure for the encapsulated Throwable if this instance represents failure.

Note, that this function rethrows any Throwable exception thrown by onSuccess or onFailure.

Since

0.4.0


fun <R, T> DecodingResult<T>.fold(onSuccess: (value: T) -> R, onSchemaMismatch: (JsonElement, exception: Throwable) -> R, onFailure: (exception: Throwable) -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success, the result of onSchemaMismatch for the encapsulated JsonElement and Throwable if this instance represents a schema mismatch, or the result of onFailure for the encapsulated Throwable if this instance represents any other failure.

Note, that this function rethrows any Throwable exception thrown by onSuccess, onFailure or onSchemaMismatch.

Since

0.4.0