kOptional

Additional

Language
Kotlin
Version
1.0.1 (Nov 21, 2016)
Created
Nov 20, 2016
Updated
Dec 27, 2016
Owner
stepango
Contributor
stepango
1
Activity
Badge
Generate
Download
Source code

Commercial

kOptional

Extended Java8 Optional Kotlin back-port for Android and JVM

Add kOptional to your build.gradle

compile "com.stepango.koptional:koptional:1.1.0"

Usage example:

arrayOf(null, "1", null, "2", null, "3")
        .map { it.toOptional() }
        .mapIndexed { i, optional -> optional.ifEmpty { Log.e("kOptional", "$i element is null, it's bad") } }
        .map { it.map { "$it is not null " } }
        .forEach { it.ifPresent(::println) }

// 1 is not null 
// 2 is not null 
// 3 is not null

Log:

// 0 element is null, it's bad
// 2 element is null, it's bad
// 4 element is null, it's bad