From a26840f6705a0419206da372216c2447a49ce784 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 26 Mar 2025 22:38:27 +0700 Subject: [PATCH] sumOfDecimal --- .../ru/dbotthepony/mc/otm/core/collect/Iterables.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/Iterables.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/Iterables.kt index 4c1a23635..3b73cab8a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/Iterables.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/collect/Iterables.kt @@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntCollection import it.unimi.dsi.fastutil.ints.IntIterable import it.unimi.dsi.fastutil.ints.IntIterator import it.unimi.dsi.fastutil.ints.IntSortedSet +import ru.dbotthepony.mc.otm.core.math.Decimal fun IntRange.asIterable(): IntIterable { return IntIterable { @@ -52,3 +53,15 @@ fun IntSortedSet.ktIterator(fromElement: Int): kotlin.collections.IntIterator { } } } + +inline fun Iterable.sumOfDecimal(selector: (T) -> Decimal): Decimal { + var result = Decimal.ZERO + forEach { result += selector(it) } + return result +} + +inline fun Iterator.sumOfDecimal(selector: (T) -> Decimal): Decimal { + var result = Decimal.ZERO + forEach { result += selector(it) } + return result +}