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:
2020-03-14 14:10:31 +01:00
parent 5b03f55cd4
commit d3f6138a8b
8 changed files with 60 additions and 54 deletions

View File

@@ -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)
}
}

View File

@@ -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")
}