Scala forall example?

前端 未结 3 1620
灰色年华
灰色年华 2021-01-31 07:44

I tried Google search and could not find a decent forall example. What does it do? Why does it take a boolean function?

Please point me to a reference (exce

3条回答
  •  灰色年华
    2021-01-31 08:17

    Scala's forall is also a great tool to do something like applying logical and to a list of boolean values with the early exist:

    val evalResults: List[Boolean] = List(evaluateFunc1(), evaluateFunc2(), evaluateFunc3(), evaluateFunc4(), evaluateFunc5())
    
    evalResults.forall(result => result == true)
    

提交回复
热议问题