fold

inline fun <VALUE, NEW_VALUE> Result<VALUE>.fold(onSuccess: (VALUE) -> NEW_VALUE, onError: (Throwable) -> NEW_VALUE): NEW_VALUE

Returns the the result of onSuccess for encapsulated value if this instance represents Success or the result of onError function for encapsulated exception if it is Error.

If Error.error is CancellationException then this error is rethrown.