Skip to content

Instantly share code, notes, and snippets.

@yayaa
Last active January 9, 2019 22:18
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 yayaa/8a181b4923d708ac06a520d5b81f64a7 to your computer and use it in GitHub Desktop.
Save yayaa/8a181b4923d708ac06a520d5b81f64a7 to your computer and use it in GitHub Desktop.
Improving the code - 1
data class Fruit(
val name: String?,
val isRotten: Boolean,
val color: Color
)
fun getFruits(): List<Fruit> { TODO() }
fun main() {
val fruits = getFruits()
for(index in 0 until fruits.size) {
val fruit = fruits[index]
if (fruit.name != null && !fruit.isRotten && fruit.color == Color.ORANGE) {
println("Yay! It's an orange ${fruit.name}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment