All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.persistence.extensions.Extensions.kt Maven / Gradle / Ivy

package com.sceyt.chatuikit.persistence.extensions

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume

inline fun > Int.toEnum(): T = enumValues()[this]

fun String?.equalsIgnoreNull(other: String?): Boolean {
    return (this?.trim() ?: "") == (other?.trim() ?: "")
}

fun  List?.equalsIgnoreNull(other: List?): Boolean {
    return (this ?: listOf()) == (other ?: listOf())
}

inline fun  Array?.equalsIgnoreNull(other: Array?): Boolean {
    return (this ?: arrayOf()).contentEquals((other ?: arrayOf()))
}

fun  List.toArrayList(): ArrayList {
    return ArrayList(this)
}

inline fun  Continuation.safeResume(value: T, onExceptionCalled: () -> Unit = {}) {
    try {
        resume(value)
    } catch (ex: Exception) {
        onExceptionCalled()
    }
}

fun  MutableLiveData.asLiveData(): LiveData {
    return this
}

fun  MutableCollection.removeFirstIf(filter: (T) -> Boolean): Int {
    val each = iterator()
    var index = 0
    while (each.hasNext()) {
        if (filter(each.next())) {
            each.remove()
            return index
        }
        index++
    }
    return -1
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy