From 3e8f44166c4a4ed6e99e1676a7200ed044645224 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 7 Jul 2024 11:02:49 +0300 Subject: [PATCH] add Attributes minus --- .../space/kscience/attributes/Attributes.kt | 14 +++++++-- benchmarks/build.gradle.kts | 2 +- kmath-ast/build.gradle.kts | 30 +++++++++---------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt index 5eb93bfc0..936cf2ee2 100644 --- a/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt +++ b/attributes-kt/src/commonMain/kotlin/space/kscience/attributes/Attributes.kt @@ -140,8 +140,18 @@ public fun > Attributes( attribute: A, ): Attributes = MapAttributes(mapOf(attribute to Unit)) -public operator fun Attributes.plus(other: Attributes): Attributes = when{ +/** + * Create a new [Attributes] that overlays [other] on top of this set of attributes. New attributes are added. + * Existing attribute keys are replaced. + */ +public operator fun Attributes.plus(other: Attributes): Attributes = when { isEmpty() -> other other.isEmpty() -> this else -> MapAttributes(content + other.content) -} \ No newline at end of file +} + +/** + * Create a new [Attributes] with removed [key] (if it is present). + */ +public operator fun Attributes.minus(key: Attribute<*>): Attributes = + if (content.contains(key)) MapAttributes(content.minus(key)) else this \ No newline at end of file diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 020ef745f..9e0d095d6 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -80,7 +80,7 @@ benchmark { // Setup configurations targets { register("jvm") -// register("js") + register("js") } fun kotlinx.benchmark.gradle.BenchmarkConfiguration.commonConfiguration() { diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index a770912f3..2cd0979ae 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -4,7 +4,20 @@ plugins { kscience { jvm() - js() + js{ + nodejs { + testTask { + useMocha().timeout = "0" + } + } + + browser { + useCommonJs() + testTask { + useMocha().timeout = "0" + } + } + } native() dependencies { @@ -18,7 +31,7 @@ kscience { dependencies(jsMain) { implementation(npm("astring", "1.7.5")) - implementation(npm("binaryen", "101.0.0")) + implementation(npm("binaryen", "117.0.0")) implementation(npm("js-base64", "3.6.1")) } @@ -29,19 +42,6 @@ kscience { } kotlin { - js { - nodejs { - testTask { - useMocha().timeout = "0" - } - } - - browser { - testTask { - useMocha().timeout = "0" - } - } - } sourceSets { filter { it.name.contains("test", true) }