【问题标题】:Scala Option higher order functions instead of pattern matchingScala Option 高阶函数而不是模式匹配
【发布时间】:2016-12-19 08:54:27
【问题描述】:

下面的高阶函数等价表达式是什么?

def isRepeated:Boolean = {
  prev match {
    case Some(a) => a.prev match {
      case Some(b) => b.equals(this)
      case None => false
    }
    case None => false
  }
}

【问题讨论】:

    标签: scala pattern-matching higher-order-functions


    【解决方案1】:

    我相信这是等价的:

    def isRepeated:Boolean = prev.exists(_.prev.exists(_.equals(this)))
    

    【讨论】:

    • 是的。美丽的!一定要爱斯卡拉!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    相关资源
    最近更新 更多