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
@Composable | |
private fun FilterIcon(modifier: Modifier, onClick: () -> Unit) { | |
Box(modifier) { | |
IconButton( | |
onClick = onClick | |
) { | |
Image( | |
painter = painterResource(R.drawable.ic_filter), | |
contentDescription = "Filter Button" | |
) |
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
// Nested conditions (BAD IDEA) | |
fun logTeamMembers(teamMembers: List<String>) { | |
if (teamMembers.isEmpty()) { | |
Log.d("TAG", "It's empty") | |
} else if (teamMembers.size == 1) { | |
if (teamMembers.first() == "foo") { | |
Log.d("TAG", "The only member is foo") | |
} else { | |
Log.d("TAG", "The only member is not foo") | |
} |
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
// Noninformative way | |
fun combineLists(a1: List<Int>, a2: List<Int>): List<Int> = a1.mapIndexed { i, f -> f - a2[i] } | |
// Meaningful distinction | |
fun combinePrices(amazonPrices: List<Int>, ebayPrices: List<Int>): List<Int> = | |
amazonPrices.mapIndexed { index, amazonPrice -> amazonPrice - ebayPrices[index] } |
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
else -> if ((type.classifier as KClass<out Any>).qualifiedName == "sctestingplayground.ErrorCode") ErrorCode.TimeOut else null |
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
else -> if ((type.classifier as KClass<out Any>).findAnnotation<InstagramErrorCode>() != null) ErrorCode.TimeOut else null |
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
internal class InstagramTypeFactory : DefaultTypeFactory() { | |
override fun KParameter.createArgument(): Any? = | |
when (type.classifier) { | |
Int::class -> 0 | |
Byte::class -> 0.toByte() | |
Short::class -> 0.toShort() | |
String::class -> "" | |
Float::class -> 0f | |
Long::class -> 0L | |
List::class -> emptyList<String>() |
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
class InstagramErrorByTypeTest { | |
companion object { | |
@Suppress("unused") | |
@JvmStatic | |
private fun checkSealedClassesByType() = Stream.of( | |
Arguments.of( | |
InstagramErrorType.DeclinePost( | |
photoVideoUrl = "https://www.instagram.com/p/B_2B2nwpS5g/", | |
tags = listOf("pullup", "bodyweight"), | |
errorCode = ErrorCode.Declined, |
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
class InstagramErrorByClassTest { | |
@Nested | |
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | |
inner class MixedConstructors { | |
private val instagramErrors = mutableListOf<String>() | |
@AfterAll | |
fun check() { |
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
@InstagramErrorCode | |
enum class ErrorCode { | |
Declined, | |
OverLimit, | |
TimeOut | |
} |
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
sealed class InstagramErrorType : InstagramErrorContent { | |
data class DeclinePost( | |
override val photoVideoUrl: String, | |
override val tags: List<String>, | |
override val errorCode: ErrorCode, | |
val textContent: String, | |
val location: String | |
) : InstagramErrorType() |