Skip to content

Instantly share code, notes, and snippets.

@sczerwinski
Created July 23, 2019 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sczerwinski/b13c473106f34a80302f6b26e3300847 to your computer and use it in GitHub Desktop.
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
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