From 853464d885b9dad1948fe2098ef0f93106f43028 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sat, 8 Jun 2024 20:37:18 +0200 Subject: Feature: Add location rabbit requirement tracker (#1997) Co-authored-by: Cal --- .../at/hannibal2/skyhanni/utils/CollectionUtils.kt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') 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 Iterator.consumeWhile(block: (T) -> R): R? { + while (hasNext()) { + return block(next()) ?: continue + } + return null + } + + inline fun Iterator.collectWhile(block: (T) -> Boolean): List { + return collectWhileTo(mutableListOf(), block) + } + + inline fun > Iterator.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 MutableSet.refreshReference(newValue: T) = if (this.contains(newValue)) { this.remove(newValue) -- cgit