diff options
| author | Linnea Gräf <nea@nea.moe> | 2024-06-04 15:49:59 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2024-06-04 15:49:59 +0200 |
| commit | 9b214189ee2f2e652f1b9d3405739b9a749ff4a8 (patch) | |
| tree | 56422b8c4b4e2d7c8ad8ef00ee4b13cecc7ff1ae /src/main/java/at/hannibal2/skyhanni/utils | |
| parent | efcebe42a9cc2ed20ec78c2114c69d7abdc59380 (diff) | |
| download | SkyHanni-beta.tar.gz SkyHanni-beta.tar.bz2 SkyHanni-beta.zip | |
Add location rabbit requirement trackerbeta
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt | 24 |
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 2e1237fe8..05b99c982 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -182,6 +182,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) |
