Fixed value delegate

This commit is contained in:
Alexander Nozik 2019-04-30 21:42:56 +03:00
parent 459e570437
commit a56fa74ab6
2 changed files with 5 additions and 4 deletions

View File

@ -75,7 +75,7 @@ class ValueDescriptor(override val config: Config) : Specific {
*
* @return
*/
var type: List<ValueType> by value().map {
var type: List<ValueType> by value {
it?.list?.map { v -> ValueType.valueOf(v.string) } ?: emptyList()
}
@ -83,7 +83,7 @@ class ValueDescriptor(override val config: Config) : Specific {
this.type = listOf(*t)
}
var tags: List<String> by value().map { value ->
var tags: List<String> by value { value ->
value?.list?.map { it.string } ?: emptyList()
}
@ -106,7 +106,7 @@ class ValueDescriptor(override val config: Config) : Specific {
*
* @return
*/
var allowedValues: List<Value> by value().map {
var allowedValues: List<Value> by value {
it?.list ?: if (type.size == 1 && type[0] === ValueType.BOOLEAN) {
listOf(True, False)
} else {

View File

@ -1,5 +1,6 @@
package hep.dataforge.meta
import hep.dataforge.values.Null
import hep.dataforge.values.Value
import kotlin.jvm.JvmName
@ -9,7 +10,7 @@ import kotlin.jvm.JvmName
/**
* A property delegate that uses custom key
*/
fun <T> Configurable.value(default: T, key: String? = null) =
fun Configurable.value(default: Any = Null, key: String? = null) =
MutableValueDelegate(config, key, Value.of(default))
fun <T> Configurable.value(default: T? = null, key: String? = null, transform: (Value?) -> T) =