Scala dynamic datatype and operators

爱⌒轻易说出口 提交于 2019-12-24 11:29:24

问题


I have a json which will send me 3 fields.

attribute

operator

value

for example:

attribute:total

operator: >=

value:1000

In scala I want to compare that field_name value, against that condition_value, according to that operator

 if($cart[$field_name][$operator][$condition_value]) 
//means if(cart['total']>=100)
    return true
    else
    return false

Operators will be dynamic. Datatype of values will be dynamic, for example condition_value can be string or number. Can I achieve it in scala / play framework?

sample scala code of what I am trying to do (non working), rule is my input

val operator=rule.operator
     val datatype="Int"
             if((cart.\(rule.attribute.get)).as[datatype](operator)rule.value.as[datatype])
                return true;
             else
                return false;
             }

Thanks.

来源:https://stackoverflow.com/questions/27482488/scala-dynamic-datatype-and-operators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!