Use logical operator as combine closure in reduce

前端 未结 6 1435
星月不相逢
星月不相逢 2020-12-15 04:01

I am trying to reduce an array of Bools by applying the logical operator OR (||) using the following code, however I get an error:

6条回答
  •  旧巷少年郎
    2020-12-15 04:38

    Swift 4.2+ / Xcode 10.0+

    In modern versions of Swift there is allSatisfy function, which checks all elements for satisfying some rule.


    In OP's case:

    values.allSatisfy { $0 }
    

提交回复
热议问题