SubwayTooter-Android-App/app/src/main/java/jp/juggler/util/CollectionUtils.kt

14 lines
396 B
Kotlin

package jp.juggler.util
// same as x?.let{ dst.add(it) }
fun <T> T.addTo(dst: ArrayList<T>) = dst.add(this)
fun <E : List<*>> E?.notEmpty(): E? =
if (this?.isNotEmpty() == true) this else null
fun <E : Map<*, *>> E?.notEmpty(): E? =
if (this?.isNotEmpty() == true) this else null
fun ByteArray?.notEmpty(): ByteArray? =
if (this?.isNotEmpty() == true) this else null