← Docs
kotlin-stdlib / kotlin / fold

fold

Common
JVM
JS
Native
1.3
inline fun < R , T > Result < T > . fold (
onSuccess : ( value : T ) -> R ,
onFailure : ( exception : Throwable ) -> R
) : R

(source)

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

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

Stay in touch:
  • Contributing to Kotlin
  • Releases
  • Press Kit
  • Security
  • Blog
  • Issue Tracker
  • Brand assets
  • Careers
Supported and developed by JetBrains .
Kotlin™ is protected under the Kotlin Foundation
and licensed under the Apache 2 license .