带有空格的 Scala XML 模式
是否存在与以下模式匹配的 xml
值?
xml match { case <foo> { x } </foo> => 42 }
Is there a value of xml
which will match the following pattern?
xml match { case <foo> { x } </foo> => 42 }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
我认为您的困惑之处在于它与不匹配。 33
这是因为当您使用
{}
时,scala 会在{}
前后的空格中插入额外的元素,因此您得到三个元素,而不是一个。您可以通过调用unapplySeq
(这是用于模式匹配的)来查看这一点:请注意,在第二个示例中,您在 ArrayBuffer 中获得了三个元素,而在第一个示例中仅获得了一个元素。所以模式不正确匹配。
Yes.
I think where your confusion comes in is it doesn't match against
<foo> 33 </foo>
This is because when you use the
{}
, scala inserts extra elements for the spaces before and after the{}
, so you get three elements, not one. You can see this by callingunapplySeq
(which is what is used for the pattern matching):Notice in the second example, you're getting three elements in the ArrayBuffer, and only one in the first. So the pattern doesn't match correctly.