【问题标题】:Checking whether a value is of type Vector via pattern matching通过模式匹配检查值是否为 Vector 类型
【发布时间】:2013-12-09 17:41:40
【问题描述】:

我需要创建一个匹配语句来检查值是否为 Vector。元素的类型可能会有所不同,我只需要在输入是 Vector 时做一个案例。我这样写代码:

symbValue match {
        ......
        case symbValue: Vector[_] => symbValue.foldleft("")((acc, value) => ....)
        ......

我得到编译错误:

value foldleft is not a member of scala.collection.immutable.Vector[_]

如何进行这种类型的模式匹配?还能做到吗?

【问题讨论】:

    标签: scala design-patterns types matching


    【解决方案1】:

    foldLeft 使用大写“L”。您的代码运行良好,除非出现拼写错误。

    【讨论】:

    • 我认为这只是那些日子之一。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 2018-07-18
    • 2012-09-17
    • 2021-10-25
    • 2019-08-25
    • 2010-10-13
    相关资源
    最近更新 更多