Created
June 19, 2021 14:48
-
-
Save marenovakovic/bb6aec03868f266504f60c82bfeb0e68 to your computer and use it in GitHub Desktop.
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
data class Topping( | |
val id: String, | |
val name: String, | |
) | |
data class Article( | |
val id: String, | |
val name: String, | |
val toppings: MutableList<Topping> = mutableListOf(), | |
) { | |
operator fun plusAssign(topping: Topping) { | |
toppings += topping | |
} | |
} | |
data class Cart( | |
val id: String, | |
val articles: MutableList<Article> = mutableListOf(), | |
) { | |
operator fun plusAssign(article: Article) { | |
articles += article | |
} | |
} | |
fun main() { | |
val currentState = CardState.Collapsed | |
val newState = !currentState | |
val topping = Topping("id", "Topping") | |
val article = Article("id", "Article") | |
val cart = Cart("id") | |
article += topping | |
cart += article | |
} | |
enum class CardState { Collapsed, Expanded, } | |
operator fun CardState.not() = | |
if (this == CardState.Collapsed) CardState.Expanded | |
else CardState.Collapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment