kotlin-unwrap

General

Category
Free
Tag
Kotlin
License
Apache License, Version 2.0
Registered
Jul 31, 2016
Favorites
0
Link
https://github.com/importre/kotlin-unwrap
See also
KLIPS
Kotlin Jetpack
kotlinpoet
Kotgo
Kursor

Additional

Language
Kotlin
Version
0.3.2 (Jun 27, 2017)
Created
Jul 20, 2016
Updated
Jun 27, 2017
Owner
Jaewe Heo (importre)
Contributor
Jaewe Heo (importre)
1
Activity
Badge
Generate
Download
Source code

Announcement

kotlin-unwrap

🎁📦💝🎁📦💝🎁📦💝

Unwrap nullable variables

build.gradle

repositories {
    jcenter()
}

dependencies {
    compile "com.importre:kotlin-unwrap:<VERSION>"
}

Example

// returns nullable
fun foo(name: String?): String? = name

val _a = foo("Hello")
val _b = foo("World")
val _c = foo("!")

// example: unwrap all variables
unwrap(_a, _b, _c) { a, b, c ->
    println("$a, $b$c") // invoked
}

Error handling using otherwise

val _a = foo("Hello")
val _b = foo("World")
val _c = foo(null)

// example: error handing
unwrap(_a, _b, _c) { a, b, c ->
    println("$a, $b$c") // not invoked
} otherwise {
    println("Nah!")     // invoked because `_c` is null
}

Test

$ ./gradlew check

License

Apache 2.0 © Jaewe Heo