Refactor code (rename allTypes matcher to anyType) and create unwrap*() methods which converts wrapped with Value values to raw Kotlin's objects
This commit is contained in:
@@ -3,12 +3,12 @@ package io.smnp.ext.lang.function
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.type.matcher.Matcher.Companion.allTypes
|
||||
import io.smnp.type.matcher.Matcher.Companion.anyType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class TypeOfFunction : Function("typeOf") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple(allTypes()) body { _, (obj) ->
|
||||
new function simple(anyType()) body { _, (obj) ->
|
||||
Value.string(obj.typeName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import io.smnp.callable.method.MethodDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.error.EvaluationException
|
||||
import io.smnp.type.enumeration.DataType.MAP
|
||||
import io.smnp.type.matcher.Matcher.Companion.allTypes
|
||||
import io.smnp.type.matcher.Matcher.Companion.anyType
|
||||
import io.smnp.type.matcher.Matcher.Companion.ofType
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class MapAccessMethod : Method(ofType(MAP), "get") {
|
||||
override fun define(new: MethodDefinitionTool) {
|
||||
new method simple(allTypes()) body { _, obj, (key) ->
|
||||
new method simple(anyType()) body { _, obj, (key) ->
|
||||
val map = (obj.value as Map<Value, Value>)
|
||||
map[key] ?: throw EvaluationException("Key '${key.value}' not found")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user