Created
April 18, 2019 15:22
-
-
Save hkusu/946e30121f55f863aca491c776abbba0 to your computer and use it in GitHub Desktop.
suspend function が利用できる map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <T, U> LiveData<T>.map( | |
scope: CoroutineScope, | |
crossinline block: suspend (T) -> U | |
): LiveData<U> { | |
val result = MediatorLiveData<U>() | |
result.addSource(this) { | |
scope.launch { | |
result.postValue(block.invoke(it)) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment