如何检查斯卡拉比赛的情况下运营商 [英] How to check operators in Scala match case

查看:117
本文介绍了如何检查斯卡拉比赛的情况下运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我送等的算术运算:A + B到我的节目时,节目内我读每一部分,并设置参数变量,x是另一个恒定变量I有和操作者。运营商将被送入ARGS(1)​​,然后根据我有什么,我想使用其他程序执行的操作。下面是我解释了计划的一部分:

I am sending an arithmetic operation like: a + b to my program, inside the program I am reading each part and set the param variable , x is another constant variable I have and the operator. Operator will be feed into args(1) then based on what I have I wanna perform an action using another program. The following is a part of the program that I explained:

 if (param != 0){
            args(1) match {
                    case + =>val resRDD=sv.apply(sRDD, x:Float=>x + param)
                    case - =>val resRDD = sv.apply(sRDD, x:Float=>x - param)
                    case * =>val resRDD = sv.apply(sRDD, x:Float=>x * param)
                    case / =>val resRDD = sv.apply(sRDD, x:Float=>x / param)
                    case _ => "error"
            }
    }

和我收到以下错误:

 [error]     ')' expected but identifier found.
 [error]           case * =>val resRDD = sv.apply(sRDD, x:Float=>x * param)
 [error]                                                           ^                                                   

当我注释此行了,我得到像所有的运营商下面的一大堆错误的:

And when I comment this line out I get whole bunch of error like the following for all operators:

[error] case + =>val resRDD=sv.apply(sRDD, x:Float=>x + param)
[error]      ^
[error] case + =>val resRDD=sv.apply(sRDD, x:Float=>x + param)
[error]                                               ^

如果我用

   case "+" => //whatever

我会收到以下错误:

I will get the following error:

   [error]  not fount: type +

我不知道什么是错我的程序!

I don't what is wrong with my program!

谢谢!

推荐答案

感谢大家,我能够把它解决如下:

Thanks to you all, I was able to solve it as follow:

  if (param != 0) {
     args(1) match {
          case "+" => val resRDD = sv.apply(sRDD, (x => x + param):Float => Float)
          case "-" => val resRDD = sv.apply(sRDD, (x => x - param):Float => Float)
          case "*" => val resRDD = sv.apply(sRDD, (x => x * param):Float => Float)
          case "/" => val resRDD = sv.apply(sRDD, (x => x / param):Float => Float)
          case _ => "error"
 }
}

这篇关于如何检查斯卡拉比赛的情况下运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆