Created
July 23, 2019 09:26
-
-
Save sczerwinski/b13c473106f34a80302f6b26e3300847 to your computer and use it in GitHub Desktop.
Representation of Android String, which is either a string or a string resource
This file contains hidden or 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
import android.content.Context | |
import androidx.annotation.StringRes | |
import it.czerwinski.kotlin.util.Either | |
import it.czerwinski.kotlin.util.Left | |
import it.czerwinski.kotlin.util.Right | |
import it.czerwinski.kotlin.util.merge | |
typealias AndroidString = Either<Int, String> | |
fun AndroidString(string: String): AndroidString = Right(string) | |
fun AndroidString(@StringRes resId: Int): AndroidString = Left(resId) | |
fun AndroidString.getString(context: Context): String = left.map(context::getString).merge() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment