summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-08 20:37:18 +0200
committerGitHub <noreply@github.com>2024-06-08 20:37:18 +0200
commit853464d885b9dad1948fe2098ef0f93106f43028 (patch)
treeeb2064e2ff6fe4367d8e6fbd801da23b56314eaf /src/main/java/at/hannibal2/skyhanni/utils
parent5bb98aed61e4dadba12d203aad770d0408171ef3 (diff)
downloadskyhanni-853464d885b9dad1948fe2098ef0f93106f43028.tar.gz
skyhanni-853464d885b9dad1948fe2098ef0f93106f43028.tar.bz2
skyhanni-853464d885b9dad1948fe2098ef0f93106f43028.zip
Feature: Add location rabbit requirement tracker (#1997)
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
index 48cf1ccb2..6b4d70046 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
@@ -184,6 +184,30 @@ object CollectionUtils {
}
}
+ inline fun <T, R> Iterator<T>.consumeWhile(block: (T) -> R): R? {
+ while (hasNext()) {
+ return block(next()) ?: continue
+ }
+ return null
+ }
+
+ inline fun <T> Iterator<T>.collectWhile(block: (T) -> Boolean): List<T> {
+ return collectWhileTo(mutableListOf(), block)
+ }
+
+ inline fun <T, C : MutableCollection<T>> Iterator<T>.collectWhileTo(collection: C, block: (T) -> Boolean): C {
+ while (hasNext()) {
+ val element = next()
+ if (block(element)) {
+ collection.add(element)
+ } else {
+ break
+ }
+ }
+ return collection
+ }
+
+
/** Updates a value if it is present in the set (equals), useful if the newValue is not reference equal with the value in the set */
inline fun <reified T> MutableSet<T>.refreshReference(newValue: T) = if (this.contains(newValue)) {
this.remove(newValue)