Skip to content

Instantly share code, notes, and snippets.

@marenovakovic
Created June 19, 2021 14:48
Show Gist options
  • Save marenovakovic/bb6aec03868f266504f60c82bfeb0e68 to your computer and use it in GitHub Desktop.
Save marenovakovic/bb6aec03868f266504f60c82bfeb0e68 to your computer and use it in GitHub Desktop.
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