Refactor names for AttributesBuilder behavior

This commit is contained in:
Alexander Nozik 2024-03-27 08:12:39 +03:00
parent 1be6a5ca0e
commit 461e5a7c54
3 changed files with 12 additions and 9 deletions

View File

@ -84,7 +84,7 @@ public fun <A : Attribute<Unit>> Attributes.withAttribute(attribute: A): Attribu
* Create a new [Attributes] by modifying the current one
*/
public fun <T> Attributes.modify(block: AttributesBuilder<T>.() -> Unit): Attributes = Attributes<T> {
from(this@modify)
putAll(this@modify)
block()
}

View File

@ -34,13 +34,18 @@ public class AttributesBuilder<out O> internal constructor(
set(this, value)
}
public fun from(attributes: Attributes) {
public infix fun <V> Attribute<V>.put(value: V?) {
set(this, value)
}
/**
* Put all attributes for given [attributes]
*/
public fun putAll(attributes: Attributes) {
map.putAll(attributes.content)
}
public fun <V> SetAttribute<V>.add(
attrValue: V,
) {
public infix fun <V> SetAttribute<V>.add(attrValue: V) {
val currentSet: Set<V> = get(this) ?: emptySet()
map[this] = currentSet + attrValue
}
@ -48,9 +53,7 @@ public class AttributesBuilder<out O> internal constructor(
/**
* Remove an element from [SetAttribute]
*/
public fun <V> SetAttribute<V>.remove(
attrValue: V,
) {
public infix fun <V> SetAttribute<V>.remove(attrValue: V) {
val currentSet: Set<V> = get(this) ?: emptySet()
map[this] = currentSet - attrValue
}

View File

@ -43,7 +43,7 @@ public object CMOptimizerData : SetAttribute<SymbolIndexer.() -> OptimizationDat
* Specify Commons-maths optimization data.
*/
public fun AttributesBuilder<FunctionOptimization<Double>>.cmOptimizationData(data: SymbolIndexer.() -> OptimizationData) {
CMOptimizerData.add(data)
CMOptimizerData add data
}
public fun AttributesBuilder<FunctionOptimization<Double>>.simplexSteps(vararg steps: Pair<Symbol, Double>) {