Skip to content

Instantly share code, notes, and snippets.

@Raiden18
Last active May 16, 2022 11:05
Show Gist options
  • Save Raiden18/1df9491c7a4df99c241bcf52707e396f to your computer and use it in GitHub Desktop.
Save Raiden18/1df9491c7a4df99c241bcf52707e396f to your computer and use it in GitHub Desktop.
WithListInformation
data class Product(
val title: String,
val price: BigDecimal,
val discount: BigDecimal // Value from 0.00% to 1.00%
){
val productPriceWithDiscount : BigDecimal
get() {
val discount = price * discount
return price - discount
}
}
data class Wishlist(
val products: List<Product>
){
fun getAllProductsPrice(): BigDecimal {
return products.sumOf { it.productPriceWithDiscount }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment