chore(purity): MultiFilter

This commit is contained in:
yairm210 2025-07-23 00:05:28 +03:00
parent 1620a4c231
commit 11de0ae4a3
2 changed files with 9 additions and 6 deletions

View File

@ -37,7 +37,7 @@ plugins {
// This is *with* gradle 8.2 downloaded according the project specs, no idea what that's about // This is *with* gradle 8.2 downloaded according the project specs, no idea what that's about
kotlin("multiplatform") version "1.9.24" kotlin("multiplatform") version "1.9.24"
kotlin("plugin.serialization") version "1.9.24" kotlin("plugin.serialization") version "1.9.24"
id("io.github.yairm210.purity-plugin") version "0.0.33" apply(false) id("io.github.yairm210.purity-plugin") version "0.0.34" apply(false)
} }
allprojects { allprojects {

View File

@ -1,5 +1,6 @@
package com.unciv.logic package com.unciv.logic
import yairm210.purity.annotations.LocalState
import yairm210.purity.annotations.Readonly import yairm210.purity.annotations.Readonly
import yairm210.purity.annotations.Pure import yairm210.purity.annotations.Pure
@ -20,7 +21,7 @@ object MultiFilter {
* @param filterFunction The single filter implementation * @param filterFunction The single filter implementation
* @param forUniqueValidityTests Inverts the `non-[filter]` test because Unique validity doesn't check for actual matching * @param forUniqueValidityTests Inverts the `non-[filter]` test because Unique validity doesn't check for actual matching
*/ */
@Readonly @Suppress("purity") // Calls function invoke @Readonly
fun multiFilter( fun multiFilter(
input: String, input: String,
filterFunction: (String) -> Boolean, filterFunction: (String) -> Boolean,
@ -37,13 +38,15 @@ object MultiFilter {
return filterFunction(input) return filterFunction(input)
} }
@Pure @Suppress("purity") // calls flatmap{} @Pure
fun getAllSingleFilters(input: String): Sequence<String> = when { fun getAllSingleFilters(input: String): Sequence<String> = when {
input.hasSurrounding(andPrefix, andSuffix) && input.contains(andSeparator) -> input.hasSurrounding(andPrefix, andSuffix) && input.contains(andSeparator) -> {
// Resolve "AND" filters // Resolve "AND" filters
input.removeSurrounding(andPrefix, andSuffix) @LocalState
val filters = input.removeSurrounding(andPrefix, andSuffix)
.splitToSequence(andSeparator) .splitToSequence(andSeparator)
.flatMap { getAllSingleFilters(it) } filters.flatMap { getAllSingleFilters(it) }
}
input.hasSurrounding(notPrefix, notSuffix) -> input.hasSurrounding(notPrefix, notSuffix) ->
// Simply remove "non" syntax // Simply remove "non" syntax
getAllSingleFilters(input.removeSurrounding(notPrefix, notSuffix)) getAllSingleFilters(input.removeSurrounding(notPrefix, notSuffix))