mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
chore(purity): MultiFilter
This commit is contained in:
parent
1620a4c231
commit
11de0ae4a3
@ -37,7 +37,7 @@ plugins {
|
||||
// This is *with* gradle 8.2 downloaded according the project specs, no idea what that's about
|
||||
kotlin("multiplatform") 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 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.unciv.logic
|
||||
|
||||
import yairm210.purity.annotations.LocalState
|
||||
import yairm210.purity.annotations.Readonly
|
||||
import yairm210.purity.annotations.Pure
|
||||
|
||||
@ -20,7 +21,7 @@ object MultiFilter {
|
||||
* @param filterFunction The single filter implementation
|
||||
* @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(
|
||||
input: String,
|
||||
filterFunction: (String) -> Boolean,
|
||||
@ -37,13 +38,15 @@ object MultiFilter {
|
||||
return filterFunction(input)
|
||||
}
|
||||
|
||||
@Pure @Suppress("purity") // calls flatmap{}
|
||||
@Pure
|
||||
fun getAllSingleFilters(input: String): Sequence<String> = when {
|
||||
input.hasSurrounding(andPrefix, andSuffix) && input.contains(andSeparator) ->
|
||||
input.hasSurrounding(andPrefix, andSuffix) && input.contains(andSeparator) -> {
|
||||
// Resolve "AND" filters
|
||||
input.removeSurrounding(andPrefix, andSuffix)
|
||||
@LocalState
|
||||
val filters = input.removeSurrounding(andPrefix, andSuffix)
|
||||
.splitToSequence(andSeparator)
|
||||
.flatMap { getAllSingleFilters(it) }
|
||||
filters.flatMap { getAllSingleFilters(it) }
|
||||
}
|
||||
input.hasSurrounding(notPrefix, notSuffix) ->
|
||||
// Simply remove "non" syntax
|
||||
getAllSingleFilters(input.removeSurrounding(notPrefix, notSuffix))
|
||||
|
Loading…
x
Reference in New Issue
Block a user