aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/listutil.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-05-18 14:57:07 +0200
committerLinnea Gräf <nea@nea.moe>2024-05-18 14:57:07 +0200
commita39f6e9bec3318b2be251570ea7aea29d58b49cb (patch)
treee7d93e4243c172f80111e18768f5ee7ec19fb3f5 /src/main/kotlin/moe/nea/firmament/util/listutil.kt
parentad09808c25c769be760559e1a597e29e488827bf (diff)
downloadfirmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.tar.gz
firmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.tar.bz2
firmament-a39f6e9bec3318b2be251570ea7aea29d58b49cb.zip
Fix item rarity not displaying in npc shops
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/listutil.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/listutil.kt14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/listutil.kt b/src/main/kotlin/moe/nea/firmament/util/listutil.kt
new file mode 100644
index 0000000..b72457f
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/listutil.kt
@@ -0,0 +1,14 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.util
+
+fun <T, R> List<T>.lastNotNullOfOrNull(func: (T) -> R?): R? {
+ for (i in indices.reversed()) {
+ return func(this[i]) ?: continue
+ }
+ return null
+}