Syntax Sugar

This repository provides some syntax sugar for our Sublab repositories.

OR extension for Nullable values

val nullString: String? = null
val emptyString: String = nullString.orEmpty() // ""
val defaultString: String = nullString.or("defaultValue") // "defaultValue"

val nullInt: Int32? = null
val zeroInt: Int32 = nullInt.or(0) // 0

All nullable types in Kotlin now can use .or() method to back up default value

However, there's only one custom String orEmpty extension, we look forward to adding more for basic types once we need them.

Last updated