嵌套的Scala匹配为什么Some(Some(1),1)无法匹配?
发布时间:2020-12-16 19:01:58 所属栏目:安全 来源:网络整理
导读:似乎嵌套匹配不起作用,这是一个奇怪的限制. 行为的一个例子如下: Some(Some(1),2) match { | case Some(Some(a),b) = a | case e = e | }console:9: error: wrong number of arguments for none: (x: (Some[Int],Int))Some[(Some[Int],Int)] case Some(Some
似乎嵌套匹配不起作用,这是一个奇怪的限制.
行为的一个例子如下: Some(Some(1),2) match { | case Some(Some(a),b) => a | case e => e | } <console>:9: error: wrong number of arguments for <none>: (x: (Some[Int],Int))Some[(Some[Int],Int)] case Some(Some(a),b) => a ^ <console>:9: error: not found: value a case Some(Some(a),b) => a ^ 这有效: Some(Some(1),2) match { case Some(a) => a match { case (Some(a),b) => "yay" case e => "nay" } } 现在,我只是一个蠢货还是有更好的方法来实现这一目标? 解决方法
什么是一些(一些(1),2)? (元素选项(Int)和Int)的元组选项?这有效:
scala> Some ((Some (1),2)) match { | case Some ((Some (a),b)) => a | case e => e } res13: Any = 1 注意元组周围的附加括号 – 它们中包含太少的常见错误. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容