Shortcut to "isEmpty" in UpgradeContainer to account for most common case

This commit is contained in:
DBotThePony 2025-02-22 11:54:57 +07:00
parent b4fc02b14e
commit ec68b7ee9c
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -21,12 +21,18 @@ class UpgradeContainer(
get() = setOf()
private fun positiveDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal {
if (isEmpty)
return Decimal.ZERO
return iterator()
.map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO).moreThanZero() * it.count }
.reduce(Decimal.ZERO, reducer)
}
private fun anyDecimals(fn: (IMatteryUpgrade) -> Decimal, reducer: (Decimal, Decimal) -> Decimal): Decimal {
if (isEmpty)
return Decimal.ZERO
return iterator()
.map { (it.getCapability(MatteryCapability.UPGRADE)?.let(fn) ?: Decimal.ZERO) * it.count }
.reduce(Decimal.ZERO, reducer)