Skip to content

Instantly share code, notes, and snippets.

@seoft
Last active February 19, 2020 12:06
Show Gist options
  • Save seoft/f24c5c8fb7cf72cf7ee41a7af56e14be to your computer and use it in GitHub Desktop.
Save seoft/f24c5c8fb7cf72cf7ee41a7af56e14be to your computer and use it in GitHub Desktop.
// 정의
fun String?.exist(completion: (String) -> Unit): String? {
return if (this.isNullOrBlank()) {
null
} else {
completion(this)
this
}
}
// 사용
"this_is_string_or_null".exist {
println(it)
}
// 정의
fun <T> SingleEmitter<T>.live(): SingleEmitter<T>? {
return if (this.isDisposed) {
null
} else {
this
}
}
// 사용
Single.create<Int> { emitter ->
emitter.live()?.onSuccess(123)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment